How k3s-io/k3s works
K3s is a lightweight Kubernetes distribution packaged as a multicall binary. The main workflow is an operator invoking the server or agent command: configuration reaches the server runtime, which bootstraps cluster state and starts control-plane services; worker agents connect through the documented websocket tunnel. Separate branches cover datastore and etcd snapshots, certificate management, and local-manifest deployment. The source excerpts show selected startup and controller behavior; README statements preserve additional bundled capabilities whose implementation was not sampled.
Main entry points: server/server.go Server runtime · run.go Agent runtime · server/server.go Server configuration · control/server.go Control daemons
Components 18
Commands and operations
- K3s launcher
cmd/k3s/main.go - Command definitions
pkg/cli/cmds/server.go - Server configuration
pkg/cli/server/server.go
Cluster control plane
- Server runtime
pkg/server/server.go - Control daemons
pkg/daemons/control/server.go - Embedded executor
pkg/executor/embed/embed.go - Cluster bootstrap storage
pkg/cluster/storage.go - Supervisor API
pkg/server/handlers/handlers.go
Node runtime
- Agent runtime
pkg/agent/run.go - Node websocket tunnel
pkg/agent/tunnel/tunnel.go - Container runtime
pkg/agent/containerd/containerd.go - Flannel networking
pkg/agent/flannel/flannel.go
Cluster services
- Certificate management
pkg/certmonitor/certmonitor.go - Manifest deployment
pkg/deploy/controller.go - Etcd snapshots
pkg/etcd/snapshot_controller.go - Service load balancer
pkg/cloudprovider/servicelb.go - Bundled Kubernetes services
pkg/server/server.go
Other components
- Operator
Connections 19
- Operator → K3s launcher: invokes
README.md - K3s launcher → Command definitions: dispatches commands
cmd/k3s/main.go - Command definitions → Server configuration: runs server
- Server configuration → Server runtime: configures and starts
pkg/cli/server/server.go - Server runtime → Control daemons: starts services
pkg/server/server.go - Control daemons → Embedded executor: runs components
pkg/daemons/control/server.go - Control daemons → Cluster bootstrap storage: bootstraps cluster
pkg/daemons/control/server.go - Server runtime → Supervisor API: starts API
pkg/server/server.go - Server runtime → Manifest deployment: sets up deployment
pkg/server/server.go - Server configuration → Agent runtime: starts agent
pkg/cli/server/server.go - Agent runtime → Node websocket tunnel: uses tunnel
pkg/agent/run.go - Agent runtime → Container runtime: configures runtime
pkg/agent/run.go - Agent runtime → Certificate management: monitors certificates
pkg/agent/run.go - Server runtime → Etcd snapshots: starts controllers
- Server runtime → Service load balancer: enables provider
- Agent runtime → Flannel networking: sets up networking
- Server runtime → Bundled Kubernetes services: bundles services
README.md - Server runtime → Certificate management: manages certificates
README.md - Server runtime → Node websocket tunnel: connects worker nodes
README.md