Skip to content

k3sctl ​

k3sctl is a declarative lifecycle management tool for K3s clusters, created and inspired by k0sctl. Point it at a YAML file describing your hosts and it installs, upgrades, reconfigures, backs up, and resets the cluster over SSH.

Single-node (localhost) — no SSH required:

sh
k3sctl init --localhost --name dev > k3sctl.yaml
k3sctl apply --config k3sctl.yaml
k3sctl kubeconfig --config k3sctl.yaml > kubeconfig.yaml

Multi-node (SSH) — server + agent:

sh
k3sctl init --name demo --address 10.0.0.1 --agent --agent-address 10.0.0.2 > k3sctl.yaml
k3sctl apply --config k3sctl.yaml
k3sctl kubeconfig --config k3sctl.yaml > kubeconfig.yaml

See the Quick Start guide for step-by-step instructions covering single-node, multi-node, and high-availability setups.

What it does ​

  • Declarative cluster configuration with servers and agents in one file.
  • Installs and upgrades K3s binaries from GitHub releases, a URL, a local file, or an existing installation on the host.
  • Generates server and agent configuration plus systemd units.
  • Supports labels, taints, extra install flags, environment variables, and arbitrary file uploads.
  • Applies additional Kubernetes manifests bundled in the configuration file.
  • Automated etcd snapshots with S3 upload, retention, and pruning, plus etcd member validation and restore from a snapshot.
  • Fetches a ready-to-use admin kubeconfig.
  • Idempotent apply: safe to re-run, and only changes what drifted.
  • Rolling upgrades with drain and cordon for both servers and agents.
  • Configuration validation (config validate) and diff (config diff).
  • Air-gap install: upload pre-downloaded image bundles for offline clusters.
  • Dry-run mode with --dry-run.
  • Private registry mirrors and authentication (registries).
  • Secrets encryption at rest with key rotation and re-encryption (secretsEncrypt).
  • Certificate Authority rotation (certRotate.rotateCA).
  • Cluster join token rotation (token.rotate).
  • Post-apply cluster health verification (healthCheck).
  • Pre-flight checks for cgroups, kernel modules, ports, and disk (preflight).
  • Declarative networking: cluster/service CIDRs, DNS, flannel backend, egress selector mode, NodePort range, and ServiceLB namespace (network).
  • Component disabling: turn off packaged components like traefik, servicelb, metrics-server, and individual subsystems like kube-proxy or the Helm controller (disable).
  • TLS SAN management: add Subject Alternative Names to the API server certificate (tls).
  • Kubeconfig output control: file mode, group, and cluster name (kubeconfig).
  • External datastore: MySQL, PostgreSQL, or etcd endpoint with TLS (datastore).
  • API server listener: advertise address/port, bind address, HTTPS port (server).
  • Security hardening: SELinux, kernel defaults protection, and encryption provider selection (security).
  • Typed component arguments: pass arguments directly to kube-apiserver, kube-controller-manager, kubelet, kube-proxy, etcd, and others (componentArgs).
  • Container runtime: system default registry, pause image, snapshotter, default runtime override, and custom resolv.conf (runtime).
  • Embedded container registry: enable the K3s built-in Spegel distributed registry (embeddedRegistry).
  • Image credential provider: external kubelet credential plugin for pulling images from private registries (imageCredentialProvider).
  • Per-host node networking: external IPs, internal/external DNS names for multi-homed and cloud nodes (nodeExternalIP, nodeInternalDNS, nodeExternalDNS).
  • Local storage: custom path for the built-in local-path provisioner (localStorage).
  • Advanced etcd tuning: expose metrics, disable automatic snapshots, snapshot naming, and reconcile interval (etcdAdvanced).
  • Advanced flannel options: interface selection, custom flannel and CNI configuration file paths (network.flannelIface, flannelConf, flannelCNIConf).
  • Advanced S3 snapshot storage: session tokens, bucket lookup type, proxy, config secret, timeout, and per-S3 retention (etcdSnapshots.s3).
  • Token files: read server and agent tokens from files instead of inline values (token.tokenFile, token.agentTokenFile).
  • Kubeconfig output path: write the kubeconfig to a custom location (kubeconfig.path).
  • Supervisor metrics and pprof: expose the supervisor metrics and profiling endpoints (server.supervisorMetrics, server.enablePprof).
  • Rootless mode: run K3s without root privileges, and prefer bundled binaries over host-installed versions (security.rootless, security.preferBundledBin).
  • CRI endpoint override: point K3s at a custom container runtime or image service socket (runtime.containerRuntimeEndpoint, runtime.imageServiceEndpoint).
  • Registry endpoint control: disable the default network endpoint for the embedded Spegel registry (embeddedRegistry.disableDefaultRegistryEndpoint).
  • Agent load balancer port: configure the port the agent uses to reach the control plane (agent.lbServerPort).
  • Per-host node ID: append the machine ID to the node name for uniqueness in auto-scaled or cloned environments (withNodeID).

WARNING

Linux hosts only. k3sctl drives the cluster over SSH, so each host must be reachable and must provide sudo or a root login.

How it works ​

  1. k3sctl reads the Cluster document from your config file.
  2. It connects to each host over SSH and detects the OS and architecture.
  3. It uploads or downloads the requested K3s version, writes the server or agent configuration and the systemd unit, then starts K3s.
  4. Once the API server answers, it applies any additional manifests found in the same file with kubectl apply.
  5. k3sctl kubeconfig reads the admin kubeconfig back so you can use it locally.

Because the desired state is the file, re-running apply after editing it is the normal way to change a cluster.

Requirements ​

  • Linux hosts for servers and agents (or the local machine for single-node).
  • SSH access with a key or agent (not needed for localhost mode).
  • Root or passwordless sudo on each host. k3sctl handles sudo internally — do not prefix commands with sudo.

Next steps ​

  • Quick Start: step-by-step guides for single-node, multi-node, and HA clusters.
  • Installation: release binary, go install, or build from source.
  • Configuration: every host, K3s, and drain option.
  • Commands: the full CLI and the flags accepted by apply.