K3s — Dependencies#

Module info#

  • Module: github.com/k3s-io/k3s
  • Go version: 1.25.7
  • Direct dependencies: ~100 (first require block, lines 77–176)
  • Indirect dependencies: ~347 (two additional require blocks marked // indirect)
  • go.sum entries: ~966 unique module+version pairs (1,933 lines / 2)
  • replace directives: 73 — the most architecturally distinctive feature of this go.mod

Dependency categories#

Core infrastructure#

DependencyPurpose
github.com/sirupsen/logrusPrimary logger throughout K3s source code
go.uber.org/zapUsed specifically by etcd subsystem (etcd requires zap)
github.com/urfave/cli/v2CLI framework for all subcommands (server, agent, etcd-snapshot, etc.)
github.com/spf13/pflagPOSIX flag parsing, used by embedded kubectl and k8s components
github.com/spf13/aferoFilesystem abstraction (used by kustomize/kubectl code)
github.com/joho/godotenv.env file loading for configuration
github.com/fsnotify/fsnotifyFile system event watching (manifests, configs)
github.com/robfig/cron/v3Cron scheduling for etcd snapshot rotation
github.com/blang/semver/v4Semver parsing for version checks
github.com/natefinch/lumberjackLog rotation

Kubernetes / CNCF ecosystem#

This is the dominant category by count. All k8s.io/* packages are redirected via replace to github.com/k3s-io/kubernetes/staging/src/k8s.io/* at v1.35.3-k3s1.

DependencyPurpose
k8s.io/kubernetesThe full Kubernetes source tree (redirected to k3s fork)
k8s.io/api, k8s.io/apimachinery, k8s.io/client-goCore k8s API types, client, machinery
k8s.io/apiserver, k8s.io/apiextensions-apiserverAPI server and CRD support
k8s.io/kubectl, k8s.io/kubelet, k8s.io/kube-proxyEmbedded k8s node-side binaries
k8s.io/kube-scheduler, k8s.io/kube-controller-managerEmbedded control plane components
k8s.io/component-base, k8s.io/component-helpersShared k8s component utilities
k8s.io/klog/v2Kubernetes structured logging (redirected to k3s fork)
k8s.io/utilsMisc k8s utility functions
sigs.k8s.io/cri-toolscrictl/ctr tooling (redirected to k3s fork)
sigs.k8s.io/yamlYAML ↔ JSON conversion for k8s objects
github.com/k3s-io/apiK3s-specific CRD types
github.com/k3s-io/helm-controllerHelm chart controller for automatic chart deployment

Container runtime / OCI#

DependencyPurpose
github.com/containerd/containerd/v2Embedded containerd runtime (redirected to k3s fork)
github.com/containerd/containerd/apicontainerd API types
github.com/containerd/cgroups/v3cgroup v1/v2 management
github.com/containerd/fuse-overlayfs-snapshotter/v2Rootless-friendly overlay snapshotter
github.com/containerd/stargz-snapshotterLazy-pull container image snapshotter
github.com/containerd/zfs/v2ZFS snapshotter support
github.com/Mirantis/cri-dockerdDocker CRI shim (redirected to k3s fork)
github.com/Microsoft/hcsshimWindows container support
github.com/opencontainers/cgroupsOCI cgroup utilities
github.com/opencontainers/go-digest, image-spec, selinuxOCI image and runtime spec primitives
github.com/google/cadvisorContainer resource monitoring (redirected to k3s fork)
github.com/pdtpartners/nix-snapshotterNix-based immutable container snapshotter
github.com/docker/dockerDocker engine client (used for Docker runtime integration)
github.com/google/go-containerregistryOCI image manipulation, used by image pulls

Networking / HTTP#

DependencyPurpose
github.com/flannel-io/flannelEmbedded CNI network overlay plugin
github.com/cloudnativelabs/kube-router/v2Embedded kube-router for network policy and routing (redirected to k3s fork)
github.com/vishvananda/netlinkLinux netlink (iproute2 equivalent) for network configuration
github.com/coreos/go-iptablesiptables rule management
github.com/yl2chen/cidrangerEfficient CIDR range lookup for IP routing
github.com/inetaf/tcpproxyTCP proxy for load-balancer mode
github.com/gorilla/websocketWebSocket support (used by remotedialer/tunnel)
github.com/mwitkow/go-http-dialerHTTP CONNECT tunneling for proxy environments
github.com/libp2p/go-libp2pP2P networking stack, used by Spegel for image distribution
golang.org/x/netExtended network stdlib (HTTP/2, proxy utilities)
google.golang.org/grpcgRPC for etcd, containerd, and k8s component communication

Data / Storage#

DependencyPurpose
github.com/k3s-io/kineK3s’s etcd shim — enables SQLite/MySQL/Postgres/NATS as k8s datastore
go.etcd.io/etcd/server/v3Embedded etcd server (redirected to k3s fork)
go.etcd.io/etcd/client/v3etcd client library
go.etcd.io/etcd/api/v3, client/pkg/v3, etcdutl/v3etcd API types and utilities
github.com/minio/minio-go/v7S3-compatible client for etcd snapshot backup to object storage
github.com/mattn/go-sqlite3SQLite driver, the default Kine backing store (indirect, pulled by kine)
github.com/go-sql-driver/mysqlMySQL driver for Kine (indirect)
github.com/jackc/pgx/v5Postgres driver for Kine (indirect)
github.com/ipfs/go-ds-leveldbLevelDB datastore, used by Spegel/libp2p for peer discovery persistence
github.com/coreos/go-systemd/v22systemd integration (socket activation, journal logging)

Rancher ecosystem#

K3s carries a strong dependency on the Rancher controller framework. These packages form K3s’s “controller layer”.

DependencyPurpose
github.com/rancher/wrangler/v3Rancher’s Kubernetes controller framework (code generation, apply, leader election)
github.com/rancher/dynamiclistenerTLS cert management with automatic SANS and rotation
github.com/rancher/lassoHigh-performance shared informer factory (replaces standard k8s informers)
github.com/rancher/remotedialerReverse WebSocket tunnel for agent→server communication
github.com/rancher/wharfieContainer image puller used to fetch bundled components
github.com/rancher/permissionsRBAC/permission policy helpers

P2P image distribution (Spegel)#

DependencyPurpose
github.com/spegel-org/spegelCluster-local OCI registry mirror over libp2p (redirected to k3s fork)
github.com/libp2p/go-libp2plibp2p host, DHT, and transport
github.com/libp2p/go-libp2p-kad-dhtKademlia DHT for peer discovery
github.com/ipfs/go-log/v2Logging package used internally by libp2p

Observability#

DependencyPurpose
github.com/prometheus/client_golangPrometheus metrics exposition (redirected to pinned fork)
github.com/prometheus/commonShared Prometheus types (redirected to pinned fork)
go.opentelemetry.io/otel and sub-packagesOpenTelemetry tracing support (indirect, brought in by k8s apiserver)

Testing#

DependencyPurpose
github.com/onsi/ginkgo/v2BDD test framework (used in tests/e2e/ integration suite)
github.com/onsi/gomegaMatcher/assertion library for Ginkgo
github.com/stretchr/testifyUnit test assertions
go.uber.org/mockGo mock generation (replaces golang/mock)
github.com/go-test/deepDeep equality comparisons for test assertions

Other notable#

DependencyPurpose
github.com/rootless-containers/rootlesskitRootless Kubernetes support (user-namespace-based network/mount isolation)
github.com/moby/sys/reexec, usernsProcess re-exec and user namespace helpers from Moby
github.com/erikdubbelboer/gsptLinux process title modification (sets argv[0] to component name)
github.com/otiai10/copyRecursive file copy utility
github.com/json-iterator/goDrop-in fast JSON encoder/decoder
github.com/klauspost/compressFast compression (used by stargz, minio, and transport layers)
github.com/dustin/go-humanizeHuman-readable sizes/times for CLI output
gopkg.in/yaml.v2YAML parsing used in config file loading

Stdlib reliance#

K3s uses the stdlib heavily and directly — it is not a pure library project. The most-used stdlib packages, evidenced across key source files:

  • context — pervasive; every significant operation is context-aware for cancellation
  • net, net/http, net/url — direct HTTP/TCP server and client code throughout
  • crypto/tls, crypto/x509, crypto/rand — PKI operations for mTLS everywhere (certificates managed by dynamiclistener)
  • os, path/filepath — extensive filesystem operations for config, certs, data dirs
  • syncsync.WaitGroup, sync.Mutex used directly; not hidden behind frameworks
  • encoding/json, encoding/pem, encoding/hex — serialization at API and cert boundaries
  • fmt, strings, strconv — standard string/format utilities
  • io, bufio — streaming I/O for config reading and HTTP responses
  • time — timeouts, intervals, retries throughout

Third-party packages are used where the stdlib is insufficient: gRPC (not in stdlib), Flannel (CNI), etcd (distributed storage), libp2p (P2P networking). The pattern is: stdlib for control flow and I/O, third-party for protocol-level heavy lifting.

Shared dependencies#

Dependencies shared with other projects in the 50-project analysis set, creating cross-project connection points:

DependencyAlso used by
github.com/prometheus/client_golangVirtually all CNCF projects: Prometheus, Grafana, etcd, Traefik, Caddy
github.com/sirupsen/logrusTraefik, many Docker/container ecosystem projects
go.etcd.io/etcd/*etcd (P03), directly — K3s embeds and forks the same etcd codebase
google.golang.org/grpcetcd, Kubernetes, virtually all gRPC-based services
github.com/stretchr/testifyNear-universal across all analyzed projects
github.com/spf13/pflag, spf13/cobraKubernetes, Hugo, many CLI tools
sigs.k8s.io/yaml, gopkg.in/yaml.v2/v3All k8s-adjacent projects
k8s.io/client-goAny project that talks to a Kubernetes API server
github.com/onsi/ginkgo/v2 / gomegaKubernetes itself, etcd
github.com/containerd/containerd/v2Any OCI-native container project
github.com/gorilla/mux, gorilla/websocketTraefik, many HTTP-based projects
github.com/google/uuidWidely shared utility across most analyzed projects

Vendoring#

K3s does not vendor. There is no vendor/ directory in the repository. All dependencies are resolved via the Go module proxy and Go toolchain at build time.

The trade-off is managed differently: instead of vendoring, K3s uses an extensive set of replace directives (73 total) to pin all critical dependencies to specific forks maintained under github.com/k3s-io/*. This achieves reproducibility and patch control without the storage overhead of vendoring — particularly important given the scale of the k8s dependency tree (hundreds of packages).

The build system uses go build with Go modules and likely a GOFLAGS or -mod=mod equivalent to ensure reproducible builds from the module cache.

Notable dependency decisions#

  1. replace directives as the patching mechanism — K3s’s entire downstream maintenance strategy is encoded in go.mod. All 28 k8s.io/* packages are redirected to github.com/k3s-io/kubernetes/staging/src/k8s.io/* at v1.35.3-k3s1. Similarly, etcd (7 packages), containerd (1), klog (2), and several other critical libraries point to K3s-maintained forks. This is the canonical example of “distribution engineering” in the Go module system: maintaining a large upstream dependency tree with surgical patches.

  2. Kine over etcd — Rather than depending on the full etcd distribution, K3s developed github.com/k3s-io/kine as a compatibility shim. This enables SQLite (default), MySQL, MariaDB, Postgres, and NATS as alternative backends via a single dependency that speaks the etcd gRPC protocol. The actual etcd is still available for HA deployments and is also embedded, making K3s dual-mode: Kine for single-node, real etcd for multi-node HA.

  3. libp2p for image distribution — The inclusion of github.com/libp2p/go-libp2p (and its ~10 transitive sub-packages) for Spegel is architecturally unusual. This brings a substantial P2P networking stack into what is otherwise a traditional client-server system, purely to enable cluster-local OCI registry mirroring without a central service.

  4. Rancher controller framework instead of controller-runtime — K3s uses rancher/wrangler/v3 and rancher/lasso rather than sigs.k8s.io/controller-runtime (the standard controller framework used by most operators). This is a significant divergence: Wrangler is Rancher-internal and generates typed informers and appliers rather than using the unstructured client approach of controller-runtime. It reflects K3s’s Rancher heritage.

  5. Two logging frameworks in parallelgithub.com/sirupsen/logrus (K3s’s own code) coexists with go.uber.org/zap (required by embedded etcd). This is a common artifact of bundling upstream components with different logging preferences.

  6. Prometheus client pinned via replace — Unlike most projects which simply use the latest Prometheus client, K3s pins prometheus/client_golang and prometheus/common via replace directives. This is likely because the embedded Kubernetes components have version conflicts that require a specific pinned version across the entire binary.

  7. Pion WebRTC as transitive dep — The pion/* packages (datachannel, dtls, ice, webrtc, stun, etc.) appear as indirect deps, pulled in by libp2p’s QUIC/WebTransport transports for NAT traversal in Spegel’s P2P networking. This is an example of a relatively exotic dependency appearing from a single architectural choice (Spegel integration).