Introducing a new way to review your PRs.

Read the announcement

replicatedhq / kots

KOTS provides the framework, tools and integrations that enable the delivery and management of 3rd-party Kubernetes applications, a.k.a. Kubernetes Off-The-Shelf (KOTS) Software.

View on GitHub

21 documents · Updated Nov 23, 2026

docs / embedded-cluster-operations

Embedded cluster node operations

Embedded cluster node operations give an operator a view of cluster nodes and a controlled path to add or remove them. The system keeps the node-join artifacts aligned with the installed cluster version, reports node health and capacity, and starts infrastructure upgrades when a release changes the cluster configuration. See Cluster installation operations for the wider install lifecycle and KOTS CLI workflows for related application workflows.

Operating model

An embedded cluster is a Kubernetes cluster managed through an installation record and an embedded-cluster operator. KOTS acts as the management surface: it reads Kubernetes node state, creates join material, serves local artifacts, and hands cluster changes to the operator.

The main operating boundaries are:

BoundaryPurpose
Installation stateDefines the active cluster version, roles, and artifact locations.
Kubernetes node stateProvides node identity, readiness, connection state, roles, resource use, and pod data.
Management APIExposes read and write actions for node operations to an authorized client.
Embedded-cluster operatorApplies installation changes and performs the long-running cluster upgrade.

Artifact lifecycle

Artifact sources

Embedded-cluster artifacts are the files and images needed to install, join, or upgrade cluster nodes. A release can carry the cluster binary, Helm charts, node images, metadata, and extra artifacts such as the KOTS and operator binaries.

For connected clusters, release data comes from the Replicated application service. For air-gapped clusters, the release points to artifacts in the local registry. The active installation records the locations that later node and upgrade operations need.

References: pkg/…/fetch.go• L126-150 pkg/…/util.go• L174-185 pkg/…/upgrade.go• L298-342

Artifact distribution

An application-only upgrade does not change the cluster configuration, but it still refreshes node-join material. KOTS therefore runs the embedded-cluster operator's artifact distribution action across the cluster before it deploys the application version.

This keeps a node added after an application upgrade on the correct cluster tool and artifact set. Air-gapped installs require the operator artifact and the local registry settings for this step.

References: pkg/…/deploy.go• L88-137 pkg/…/artifacts.go• L20-106

Artifact downloads

The management service can return the locally installed cluster binary, chart bundle, and k0s image archive. These endpoints support node joins and related cluster tooling without requiring a new download from the upstream service.

The image endpoint prefers the upgrade image archive when both the initial-install and upgrade names exist. A missing local artifact is an operational error, not a request to fetch a replacement.

References: pkg/…/handlers.go• L391-401 pkg/…/embedded_cluster_artifacts.go• L18-241

Node discovery and roles

Node inventory

The node view combines Kubernetes node records with metrics and the pods assigned to each node. It shows whether a node is connected and ready, whether it is a primary control-plane node, its software versions, its roles, pressure conditions, and used versus available CPU, memory, and pod capacity.

The cluster response also reports whether high availability is enabled. A single-node detail view uses the same health and capacity model for one named node.

References: pkg/…/embedded_cluster_get.go• L14-82 pkg/…/nodes.go• L16-52 pkg/…/node.go• L38-137 pkg/…/types.go• L6-48

Role model

Node roles describe the work a joining node can perform. The cluster configuration supplies the controller role name and any custom roles. When no controller name is set, the system uses controller as the role name.

The role list is also written onto each node through embedded-cluster role labels. This lets later node discovery reconstruct the roles that were selected during the join.

References: pkg/…/roles.go• L14-46 pkg/…/roles.go• L186-210 pkg/…/node.go• L140-166

Node joining

Join command flow

Joining starts when an authorized client selects roles and requests a join command. KOTS stores those roles under a short-lived handoff token, then builds a response with the cluster join command, node token, installation data, network checks, and current application version.

The generated commands download the cluster binary from a healthy controller's management endpoint and run its join action. The node's role selection determines whether it joins as a worker or controller and which role labels it receives.

This diagram shows how a role request becomes a node that can connect to the cluster.

sequenceDiagram
    participant Client as Management client
    participant KOTS as KOTS API
    participant K8s as Kubernetes cluster
    participant Node as New node
    Client->>KOTS: Request roles
    KOTS->>KOTS: Store roles under join token
    KOTS->>K8s: Read installation, roles, and healthy nodes
    KOTS-->>Client: Join command and connection data
    Node->>KOTS: Download cluster binary
    Node->>K8s: Run join command with role token
    K8s-->>KOTS: New node state

References: pkg/…/embedded_cluster_node_join_command.go• L20-57 pkg/…/embedded_cluster_node_join_command.go• L60-192 pkg/…/node_join.go• L49-181 pkg/…/node_join.go• L212-271

Join authorization and connectivity

The role handoff token identifies the requested roles. The cluster then creates a k0s bootstrap token for the matching node type and places it in the join response. The generated response names the internal endpoints that the new node must reach.

Only ready nodes contribute to the endpoint list. A worker needs access to controller API and k0s API ports. A controller also needs the controller etcd and kubelet paths plus kubelet access to workers. A join fails when the selected node cannot reach the required endpoints or when no healthy controller can provide the join path.

References: pkg/…/embedded_cluster_store.go• L13-69 pkg/…/node_join.go• L81-147 pkg/…/node_join.go• L150-200

Node removal and draining

Management controls

The management API exposes separate write actions for draining and deleting a named node. Both actions first verify that the target exists. The intended order is to drain workloads before deleting the node from the cluster.

The current drain and delete library actions are placeholders. The drain request starts a background action and returns before that action completes, while the delete request returns after calling a no-op action. A successful HTTP response therefore does not prove that workloads moved or that the node was removed.

References: pkg/…/handlers.go• L300-313 pkg/…/embedded_cluster_drain_node.go• L16-51 pkg/…/embedded_cluster_delete_node.go• L16-57 pkg/…/drain_node.go• L10-12 pkg/…/delete_node.go• L11-13

Deletion state

The node view marks a node as deletable only when it is unschedulable and disconnected. This reflects the safety state expected before removal. It does not itself perform the drain or delete action, and it does not replace checking the cluster after an operation.

References: pkg/…/node.go• L121-137 pkg/…/nodes.go• L74-104 pkg/…/types.go• L12-28

Monitoring and reporting

Node health and capacity

Node monitoring reads readiness and pressure conditions from Kubernetes. It reads live CPU and memory metrics when the metrics service returns them, then counts pods and attaches per-pod status and usage where available.

Missing live metrics do not make the node query fail. The response keeps the capacity values that Kubernetes provides and leaves unavailable usage fields at their default values. This makes node health useful during partial monitoring outages, but it means an empty usage value is not proof of zero use.

References: pkg/…/nodes.go• L55-91 pkg/…/node.go• L57-119

Cluster change reporting

The node watcher tracks node add and delete events and changes in node readiness. After the initial cache sync, each relevant change triggers an application information report. Embedded clusters support one application, so the report is tied to the first application associated with the downstream cluster.

References: pkg/…/watchers.go• L18-33 pkg/…/watchers.go• L36-98 pkg/…/watchers.go• L101-121 pkg/…/server.go• L120-133

Upgrade reporting

Connected clusters send start, failure, and success events for infrastructure upgrades. Air-gapped clusters do not send these events. The events identify the cluster and the change from the prior embedded-cluster version.

References: pkg/…/metrics.go• L15-73 pkg/…/metrics.go• L76-107

Cluster upgrade behavior

Upgrade decision

An infrastructure upgrade is required when a release contains embedded-cluster configuration and that configuration differs from the active installation. The system does not request an upgrade during bootstrap when no installation record exists, and it does not request one for a non-embedded cluster.

This decision separates application delivery from cluster delivery. A release can deploy only the application when its cluster configuration matches the active installation.

References: pkg/…/monitor.go• L17-49 pkg/…/deploy.go• L83-95

Application-only upgrades

When no infrastructure change is needed, the upgrade service distributes the current operator artifacts to all nodes and then creates the application deployment. The operator later processes that deployment without changing the cluster installation.

This path is important for future joins because a new node must use artifacts that match the current cluster state even when the application is the only part that changed.

References: pkg/…/deploy.go• L92-137 pkg/…/artifacts.go• L20-106

Infrastructure upgrade lifecycle

When the cluster configuration changes, the upgrade service marks the task as upgrading and starts a long-running operator upgrade in the background. The process creates a new installation from the current one, replaces its configuration and artifact locations, and invokes the embedded-cluster operator with the installation data.

The operator upgrades its own API support before it applies the new installation. It reports success or failure after the deployment is processed. Connected clusters also receive metrics for the upgrade lifecycle, while air-gapped clusters keep that reporting local.

This diagram shows the handoff from release selection to operator control.

flowchart LR
    Release[Release with cluster config] --> Compare[Compare with active installation]
    Compare -->|Same| AppOnly[Distribute artifacts]
    AppOnly --> DeployApp[Create application deployment]
    Compare -->|Different| Start[Start background cluster upgrade]
    Start --> NewInstall[Create new installation]
    NewInstall --> Operator[Run operator upgrade]
    Operator --> DeployCluster[Create deployment for upgraded cluster]
    DeployCluster --> Status[Operator reports success or failure]

References: pkg/…/upgrade.go• L40-96 pkg/…/upgrade.go• L99-185 pkg/…/deploy.go• L140-189 pkg/…/operator.go• L1180-1220

Upgrade compatibility

Available releases are checked against the current embedded-cluster version when a release declares one. The system blocks releases that require an unsupported infrastructure step, downgrade the infrastructure, or make an unallowed major version change. Required application releases can also block later releases until the required sequence is installed.

References: pkg/…/update.go• L35-89 pkg/…/update.go• L120-164 pkg/…/required.go• L21-58 pkg/…/required.go• L61-87

Change checklist

When these files or sections are changed, remember to consider these:

  • When the embedded-cluster artifact fields or their source paths change, keep connected release lookup, air-gap registry lookup, installation artifact mapping, node downloads, and operator upgrade inputs aligned.
  • When role names or role labels change, keep role discovery, controller detection, join token selection, join command labels, and node display parsing compatible.
  • When join response fields change, update both the role handoff path and the node-side join contract. The response also carries air-gap registry data, connectivity checks, installation data, and the current application version.
  • When node readiness or deletion rules change, review the endpoint list for new joins and the watcher events that report node changes.
  • When infrastructure version rules change, keep release deployability checks consistent with the installation comparison and operator upgrade path.
  • When upgrade status events change, preserve the connected-versus-air-gapped reporting split and the prior/current version meaning.

Important failure modes

TriggerConsequenceGuard
No healthy controller has an internal IPThe system cannot build a join token or a command that reaches the cluster.Keep at least one controller ready and reachable before generating a join command.
A joining node cannot reach the role-specific endpoint setThe k0s join cannot complete even when the token is valid.Use the returned TCP connection list to check controller, etcd, kubelet, and API paths for the selected role.
The active installation has no required artifact locationArtifact distribution or an infrastructure upgrade stops before the operator runs.Ensure the release or air-gap bundle includes the binary, image, chart, metadata, and required operator artifact.
Metrics service data is unavailableNode usage fields can be empty while the node query still succeeds.Use readiness, pressure, capacity, and pod count with the usage fields; do not treat missing usage as zero.
Drain or delete returns successfullyThe current backend may not have moved workloads or removed the node because both library actions are no-ops.Verify Kubernetes node and workload state after the request.
A release requests an unsupported infrastructure version changeThe release is shown as not deployable.Install the required intermediate release and follow the allowed embedded-cluster version range.

Key files

FileWhy to read it
pkg/…/handlers.goShows the authorized management routes and the unauthenticated artifact and join routes.
pkg/…/node_join.goExplains role-based join material, connectivity checks, and generated node commands.
pkg/…/node.goDefines the node health, capacity, pod, and role view.
pkg/…/nodes.goDefines the cluster-wide node inventory and readiness signals.
pkg/…/artifacts.goShows how app-only upgrades distribute artifacts to every node.
pkg/…/monitor.goDefines when an application release requires an infrastructure upgrade.
pkg/…/upgrade.goShows the handoff from a release to the embedded-cluster operator.
pkg/…/deploy.goConnects application deployment, artifact distribution, and cluster upgrade paths.
pkg/…/watchers.goShows how node changes become application information reports.
pkg/…/embedded_cluster_artifacts.goShows the local artifact downloads used by joining and cluster tooling.