K3s — Dependencies#
Module info#
- Module:
github.com/k3s-io/k3s - Go version: 1.25.7
- Direct dependencies: ~100 (first
requireblock, lines 77–176) - Indirect dependencies: ~347 (two additional
requireblocks 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#
| Dependency | Purpose |
|---|---|
github.com/sirupsen/logrus | Primary logger throughout K3s source code |
go.uber.org/zap | Used specifically by etcd subsystem (etcd requires zap) |
github.com/urfave/cli/v2 | CLI framework for all subcommands (server, agent, etcd-snapshot, etc.) |
github.com/spf13/pflag | POSIX flag parsing, used by embedded kubectl and k8s components |
github.com/spf13/afero | Filesystem abstraction (used by kustomize/kubectl code) |
github.com/joho/godotenv | .env file loading for configuration |
github.com/fsnotify/fsnotify | File system event watching (manifests, configs) |
github.com/robfig/cron/v3 | Cron scheduling for etcd snapshot rotation |
github.com/blang/semver/v4 | Semver parsing for version checks |
github.com/natefinch/lumberjack | Log 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.
| Dependency | Purpose |
|---|---|
k8s.io/kubernetes | The full Kubernetes source tree (redirected to k3s fork) |
k8s.io/api, k8s.io/apimachinery, k8s.io/client-go | Core k8s API types, client, machinery |
k8s.io/apiserver, k8s.io/apiextensions-apiserver | API server and CRD support |
k8s.io/kubectl, k8s.io/kubelet, k8s.io/kube-proxy | Embedded k8s node-side binaries |
k8s.io/kube-scheduler, k8s.io/kube-controller-manager | Embedded control plane components |
k8s.io/component-base, k8s.io/component-helpers | Shared k8s component utilities |
k8s.io/klog/v2 | Kubernetes structured logging (redirected to k3s fork) |
k8s.io/utils | Misc k8s utility functions |
sigs.k8s.io/cri-tools | crictl/ctr tooling (redirected to k3s fork) |
sigs.k8s.io/yaml | YAML ↔ JSON conversion for k8s objects |
github.com/k3s-io/api | K3s-specific CRD types |
github.com/k3s-io/helm-controller | Helm chart controller for automatic chart deployment |
Container runtime / OCI#
| Dependency | Purpose |
|---|---|
github.com/containerd/containerd/v2 | Embedded containerd runtime (redirected to k3s fork) |
github.com/containerd/containerd/api | containerd API types |
github.com/containerd/cgroups/v3 | cgroup v1/v2 management |
github.com/containerd/fuse-overlayfs-snapshotter/v2 | Rootless-friendly overlay snapshotter |
github.com/containerd/stargz-snapshotter | Lazy-pull container image snapshotter |
github.com/containerd/zfs/v2 | ZFS snapshotter support |
github.com/Mirantis/cri-dockerd | Docker CRI shim (redirected to k3s fork) |
github.com/Microsoft/hcsshim | Windows container support |
github.com/opencontainers/cgroups | OCI cgroup utilities |
github.com/opencontainers/go-digest, image-spec, selinux | OCI image and runtime spec primitives |
github.com/google/cadvisor | Container resource monitoring (redirected to k3s fork) |
github.com/pdtpartners/nix-snapshotter | Nix-based immutable container snapshotter |
github.com/docker/docker | Docker engine client (used for Docker runtime integration) |
github.com/google/go-containerregistry | OCI image manipulation, used by image pulls |
Networking / HTTP#
| Dependency | Purpose |
|---|---|
github.com/flannel-io/flannel | Embedded CNI network overlay plugin |
github.com/cloudnativelabs/kube-router/v2 | Embedded kube-router for network policy and routing (redirected to k3s fork) |
github.com/vishvananda/netlink | Linux netlink (iproute2 equivalent) for network configuration |
github.com/coreos/go-iptables | iptables rule management |
github.com/yl2chen/cidranger | Efficient CIDR range lookup for IP routing |
github.com/inetaf/tcpproxy | TCP proxy for load-balancer mode |
github.com/gorilla/websocket | WebSocket support (used by remotedialer/tunnel) |
github.com/mwitkow/go-http-dialer | HTTP CONNECT tunneling for proxy environments |
github.com/libp2p/go-libp2p | P2P networking stack, used by Spegel for image distribution |
golang.org/x/net | Extended network stdlib (HTTP/2, proxy utilities) |
google.golang.org/grpc | gRPC for etcd, containerd, and k8s component communication |
Data / Storage#
| Dependency | Purpose |
|---|---|
github.com/k3s-io/kine | K3s’s etcd shim — enables SQLite/MySQL/Postgres/NATS as k8s datastore |
go.etcd.io/etcd/server/v3 | Embedded etcd server (redirected to k3s fork) |
go.etcd.io/etcd/client/v3 | etcd client library |
go.etcd.io/etcd/api/v3, client/pkg/v3, etcdutl/v3 | etcd API types and utilities |
github.com/minio/minio-go/v7 | S3-compatible client for etcd snapshot backup to object storage |
github.com/mattn/go-sqlite3 | SQLite driver, the default Kine backing store (indirect, pulled by kine) |
github.com/go-sql-driver/mysql | MySQL driver for Kine (indirect) |
github.com/jackc/pgx/v5 | Postgres driver for Kine (indirect) |
github.com/ipfs/go-ds-leveldb | LevelDB datastore, used by Spegel/libp2p for peer discovery persistence |
github.com/coreos/go-systemd/v22 | systemd integration (socket activation, journal logging) |
Rancher ecosystem#
K3s carries a strong dependency on the Rancher controller framework. These packages form K3s’s “controller layer”.
| Dependency | Purpose |
|---|---|
github.com/rancher/wrangler/v3 | Rancher’s Kubernetes controller framework (code generation, apply, leader election) |
github.com/rancher/dynamiclistener | TLS cert management with automatic SANS and rotation |
github.com/rancher/lasso | High-performance shared informer factory (replaces standard k8s informers) |
github.com/rancher/remotedialer | Reverse WebSocket tunnel for agent→server communication |
github.com/rancher/wharfie | Container image puller used to fetch bundled components |
github.com/rancher/permissions | RBAC/permission policy helpers |
P2P image distribution (Spegel)#
| Dependency | Purpose |
|---|---|
github.com/spegel-org/spegel | Cluster-local OCI registry mirror over libp2p (redirected to k3s fork) |
github.com/libp2p/go-libp2p | libp2p host, DHT, and transport |
github.com/libp2p/go-libp2p-kad-dht | Kademlia DHT for peer discovery |
github.com/ipfs/go-log/v2 | Logging package used internally by libp2p |
Observability#
| Dependency | Purpose |
|---|---|
github.com/prometheus/client_golang | Prometheus metrics exposition (redirected to pinned fork) |
github.com/prometheus/common | Shared Prometheus types (redirected to pinned fork) |
go.opentelemetry.io/otel and sub-packages | OpenTelemetry tracing support (indirect, brought in by k8s apiserver) |
Testing#
| Dependency | Purpose |
|---|---|
github.com/onsi/ginkgo/v2 | BDD test framework (used in tests/e2e/ integration suite) |
github.com/onsi/gomega | Matcher/assertion library for Ginkgo |
github.com/stretchr/testify | Unit test assertions |
go.uber.org/mock | Go mock generation (replaces golang/mock) |
github.com/go-test/deep | Deep equality comparisons for test assertions |
Other notable#
| Dependency | Purpose |
|---|---|
github.com/rootless-containers/rootlesskit | Rootless Kubernetes support (user-namespace-based network/mount isolation) |
github.com/moby/sys/reexec, userns | Process re-exec and user namespace helpers from Moby |
github.com/erikdubbelboer/gspt | Linux process title modification (sets argv[0] to component name) |
github.com/otiai10/copy | Recursive file copy utility |
github.com/json-iterator/go | Drop-in fast JSON encoder/decoder |
github.com/klauspost/compress | Fast compression (used by stargz, minio, and transport layers) |
github.com/dustin/go-humanize | Human-readable sizes/times for CLI output |
gopkg.in/yaml.v2 | YAML 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 cancellationnet,net/http,net/url— direct HTTP/TCP server and client code throughoutcrypto/tls,crypto/x509,crypto/rand— PKI operations for mTLS everywhere (certificates managed by dynamiclistener)os,path/filepath— extensive filesystem operations for config, certs, data dirssync—sync.WaitGroup,sync.Mutexused directly; not hidden behind frameworksencoding/json,encoding/pem,encoding/hex— serialization at API and cert boundariesfmt,strings,strconv— standard string/format utilitiesio,bufio— streaming I/O for config reading and HTTP responsestime— 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:
| Dependency | Also used by |
|---|---|
github.com/prometheus/client_golang | Virtually all CNCF projects: Prometheus, Grafana, etcd, Traefik, Caddy |
github.com/sirupsen/logrus | Traefik, many Docker/container ecosystem projects |
go.etcd.io/etcd/* | etcd (P03), directly — K3s embeds and forks the same etcd codebase |
google.golang.org/grpc | etcd, Kubernetes, virtually all gRPC-based services |
github.com/stretchr/testify | Near-universal across all analyzed projects |
github.com/spf13/pflag, spf13/cobra | Kubernetes, Hugo, many CLI tools |
sigs.k8s.io/yaml, gopkg.in/yaml.v2/v3 | All k8s-adjacent projects |
k8s.io/client-go | Any project that talks to a Kubernetes API server |
github.com/onsi/ginkgo/v2 / gomega | Kubernetes itself, etcd |
github.com/containerd/containerd/v2 | Any OCI-native container project |
github.com/gorilla/mux, gorilla/websocket | Traefik, many HTTP-based projects |
github.com/google/uuid | Widely 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#
replacedirectives as the patching mechanism — K3s’s entire downstream maintenance strategy is encoded in go.mod. All 28k8s.io/*packages are redirected togithub.com/k3s-io/kubernetes/staging/src/k8s.io/*atv1.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.Kine over etcd — Rather than depending on the full etcd distribution, K3s developed
github.com/k3s-io/kineas 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.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.Rancher controller framework instead of controller-runtime — K3s uses
rancher/wrangler/v3andrancher/lassorather thansigs.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.Two logging frameworks in parallel —
github.com/sirupsen/logrus(K3s’s own code) coexists withgo.uber.org/zap(required by embedded etcd). This is a common artifact of bundling upstream components with different logging preferences.Prometheus client pinned via
replace— Unlike most projects which simply use the latest Prometheus client, K3s pinsprometheus/client_golangandprometheus/commonviareplacedirectives. This is likely because the embedded Kubernetes components have version conflicts that require a specific pinned version across the entire binary.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).