k8s.io/kubernetes is massive (~2M lines). Key directories:
| Directory | What's There |
|---|---|
cmd/kubelet/ |
The kubelet binary entry point |
cmd/kube-apiserver/ |
API server entry point |
cmd/kube-controller-manager/ |
All built-in controllers |
pkg/kubelet/ |
Kubelet implementation |
pkg/controller/ |
Controller implementations |
staging/src/k8s.io/ |
Libraries published as separate modules |
Trace a kubectl get pods command:
cmd/kubectl/main.go
→ pkg/cmd/cmd.go (NewDefaultKubectlCommand)
→ pkg/cmd/get/get.go (NewCmdGet)
→ Builds a REST request to the API server
→ Uses client-go's discovery + REST client
→ HTTP GET to /api/v1/namespaces/default/pods
Reading this teaches you: CLI design, API client patterns, error handling, output formatting.
In pkg/controller/deployment/, the Deployment controller:
syncDeployment()syncDeployment() compares desired replicas vs actual ReplicaSetsThis is the exact pattern from Module 11, used in production by every K8s cluster.