Skip to content

Add container cluster start and stop - #2485

Open
adityaramani wants to merge 1 commit into
apple:mainfrom
adityaramani:cluster-start-stop
Open

adityaramani wants to merge 1 commit into
apple:mainfrom
adityaramani:cluster-start-stop

Conversation

@adityaramani

Copy link
Copy Markdown
Contributor

Closes #2440

The change adds to new sub-commands to the cluster command family

  1. cluster stop stops the nodes of a cluster. Disks and the kubeconfig entry are kept.

  2. cluster start boots the stopped nodes of a stopped or degraded cluster from its stored configuration and returns when the cluster is usable. It is a no-op on a running cluster.

Node IPs change when a node restarts, so workers join through a stable control-plane endpoint:

  1. This is the fqdn when a dns domain has been set
  2. Without an fqdn, the control-plane address is written to each worker's /etc/hosts at create and on every start.

start waits for:

  • a fresh lease renewal from every node it boots
  • the kubernetes endpoints to list only the current control-plane address and the CoreDNS pods to be Ready
  • on multi-node clusters with the default CNI, a route from every node to every other node's pod network, which kindnet restores about 30 seconds after boot.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Motivation and Context

Implement #2440

Testing

  • Tested locally
  • Added/updated tests
  • Added/updated docs

cluster stop stops the nodes of a cluster: workers in parallel, then the
control plane. It takes --name, --signal and --time (default 30
seconds). Disks and the kubeconfig entry are kept.

cluster start boots the stopped nodes of a stopped or degraded cluster
from its stored configuration and returns when the cluster is usable.
It is a no-op on a running cluster. It builds a ClusterBootstrapper from
the stored ClusterConfiguration (ClusterBootstrapper.init(configuration:
containerSystemConfig:)) and runs ClusterBootstrapper.start, with the
same progress bar pattern as create.

Node IPs change when a node restarts, so workers join through a stable
control-plane endpoint: the fqdn when the cluster has one, otherwise the
cluster name. Without an fqdn, the control-plane address is written to
each worker's /etc/hosts at create and on every start. The endpoint is
added to NO_PROXY on the nodes. Workers that are still running when the
control plane restarts are stopped and started again to pick up the new
address.

start waits for:
- a fresh Lease renewal from every node it boots, because the Ready
  conditions stored in etcd are stale after a restart;
- the kubernetes Endpoints to list only the current control-plane
  address and the CoreDNS pods to be Ready;
- on multi-node clusters with the default CNI, a route from every node
  to every other node's pod network, which kindnet restores about 30
  seconds after boot.

NodeProvisioner gains reapplyNetworkSettings (sysctls and iptables
rules that a reboot clears; iptables now uses -w) and
setControlPlaneHost. start checks the host store socket and the
virtiofs mount sources before booting any node and refreshes the
kubeconfig, warning instead of failing if that step fails.

Clusters created before this change have no controlPlaneEndpoint and
cannot restart multi-node.

createCluster, preparePodImage and waitForPod moved verbatim from
TestClusterNetworkingSerial.swift to ContainerFixture+ClusterHelpers.swift
as ContainerFixture methods. Integration tests cover single-node and
multi-node stop/start and start on a running cluster. Unit tests cover
node selection, leases, DNS and route readiness, proxy env, the
control-plane endpoint and the CNI helpers.
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Nov 9, 2026
@github-actions

Copy link
Copy Markdown

Code Coverage

Tier Line Coverage
Unit 24%
Integration 70.12%
Combined 78.6%

@SVilgelm

Copy link
Copy Markdown

Tested on an M5 Max (macOS 27.2.1), release build of main + this PR (+ #1740, #2378).

  • 1 node and 1 + 1: cluster stop/start, system stop/start + cluster start, and an in-guest node reboot + cluster start all work (~43 s for 1 node, ~49 s for 1 + 1). PVC data, a ConfigMap and a MetalLB LB IP survive.
  • 1 + 2: cluster start crashes every time (6/6, exit 134, ~6 s in):
Waiting for node to boot: ["node": p0-k8s-worker-1]
Waiting for node to boot: ["node": p0-k8s-worker-2]
*** Terminating app due to uncaught exception 'NSFileHandleOperationException',
    reason: '*** -[NSConcreteFileHandle readDataOfLength:]: Bad file descriptor'
  … ClusterHelper.waitForNodeBooted … ClusterBootstrapper.start …

Only with two or more workers, where waitForNodeBooted → execCapture runs concurrently in the task group. The cluster recovers ~47 s later, but the readiness checks and kubeconfig refresh after the boot wait are skipped.

@SVilgelm

Copy link
Copy Markdown

Root cause of the 1 + 2 crash: XPCMessage.set(key:value:) closes the descriptor it sends, and execCapture/runProbe closed it again, so the parallel boot waits closed each other's pipes. Fix: #2543 (against main). With it, 4/4 cluster start of 1 + 2 succeed in ~50 s.

@zdk

zdk commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

I tested stop/start at 983d408 on a 1 + 1 cluster, with and without a DNS domain. Full stop/start and the degraded cases (control plane down with the worker running, worker down only) all came back healthy.

One question about a start that fails part-way.

start does not stop the nodes it started when a later step fails. Every node container is then running, so the cluster state is running, and the next cluster start returns at the state == .running check in ClusterStart.swift. It prints the name and exits 0.

What I saw, on a cluster without a DNS domain:

  1. container cluster stop --name t1
  2. container cluster start --name t1, killed right after the worker container was running
  3. container cluster list shows running
  4. container cluster start --name t1 prints t1 and exits 0 in 0.1 s
  5. The worker stays NotReady. Its kubelet cannot resolve t1, because the control-plane entry in /etc/hosts was never written.

I forced this by killing the CLI. The crash reported above stops at the same point, and from reading the code a timeout in any of the waits would leave the same state.

The docs cover the recovery (cluster stop, then cluster start), and that worked for me. But the retry itself gives no hint that anything is wrong.

Would it make sense for start to stop the nodes it started when it fails, the way create tears down on failure? A failed wait would then leave the cluster stopped or degraded, and a plain retry would run the full path again.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Request]: Add container cluster stop and container cluster start.

3 participants