FreeA course by Márk Sági-Kazár on iximiuz Labs, with a browser playground for every lessonOpen the course
13 lessonsKubernetes the (Very) Hard Way, on one page

Build a Kubernetes cluster one component at a time.

The course starts with a container runtime on a single machine and ends with DNS on a three-node cluster. You install each component by hand, run it as a systemd service, and check that it works before the next one exists.

13lessons3machines2certificate authoritiesv1.34.0Kubernetes

Three machines, built from the worker up.

Hover or focus a part to see what it does and which lesson installs it. Trust shows the certificate each component uses. Traffic shows who connects to whom, and on which port. Build marks each part with its lesson. Move the slider to see the cluster after any lesson.

Show

You can turn on more than one. Scroll the diagram sideways to see all three machines.

node network 172.16.0.0/24 on eth0, gateway 172.16.0.1 control-plane172.16.0.2, no kubelet etcd :2379/var/lib/etcdown CA: /etc/etcd/pki kube-apiserver :6443Services 10.96.0.0/12authz Node,RBAC kube-schedulerwrites Pod Bindings controller-managercluster-cidr 10.244.0.0/16signs kubelet CSRs CAetcd CAkubernetes CA/etc/kubernetes/pki, sa.key bootstrap tokenSecret bootstrap-token-abcdefauto-approved CSRs via RBAC CoreDNS 172.16.0.2:53systemd unit, bind eth0, zone cluster.localwatches Services and EndpointSlices through the API server worker-1joined in lesson 9 containerdrunc v1.4.0namespace k8s.io CNI plugins/opt/cni/binbridge, loopback, portmap kubelet :10250config in /var/lib/kubelet/config.d/static Pods: /etc/kubernetes/manifests flanneldVXLAN on flannel.1cni0 10.244.0.0/24 kube-proxyiptables modeKUBE-SERVICES Pods 10.244.0.0/24podinfo, client Pods from the lessonsnameserver 172.16.0.2, search default.svc.cluster.local worker-2joined before lesson 10 containerdrunc v1.4.0namespace k8s.io CNI plugins/opt/cni/binbridge, loopback, portmap kubelet :10250config in /var/lib/kubelet/config.d/static Pods: /etc/kubernetes/manifests flanneldVXLAN on flannel.1cni0 10.244.1.0/24 kube-proxyiptables modeKUBE-SERVICES Pods 10.244.1.0/24podinfo, client Pods from the lessonsnameserver 172.16.0.2, search default.svc.cluster.local etcd CA: server cert CN=kube-apiserver CN=system:kube-scheduler CN=system:kube-controller-manager group system:bootstrappers CN=system:coredns client cert via CSR, signed by kubernetes CA client cert via CSR, signed by kubernetes CA CN=system:flannel CN=system:flannel CN=system:kube-proxy CN=system:kube-proxy :2379 :6443 :6443 :10250 VXLAN :53 :53 03 04 05 06 06 07 08 09 09 10 10 10 10 10 11 11 12

control-plane

172.16.0.2
  • etcd:2379
  • kube-apiserver:6443
  • kube-schedulerBindings
  • kube-controller-manager10.244.0.0/16
  • CoreDNS172.16.0.2:53

worker-1

pod CIDR 10.244.0.0/24
  • containerd + runck8s.io
  • kubelet:10250
  • flanneldflannel.1
  • kube-proxyiptables

worker-2

pod CIDR 10.244.1.0/24
  • containerd + runck8s.io
  • kubelet:10250
  • flanneldflannel.1
  • kube-proxyiptables

13 lessons in four parts.

Two lessons of setup, then the worker node, the control plane, and finally the cluster that joins them. Nothing is installed by a script. Each lesson downloads a release binary, writes its config and systemd unit by hand, and checks the result.

4parts
11components installed by hand
LessonPart

    What each lesson installs, and how you know it works.

    Each block lists what the lesson installs, the setting that matters most, what fails before the lesson, and the command the lesson uses to check the result. Red text is the error you get before the fix.

    01WelcomeIntroduction

    Every lesson has the same four steps.

    Download the component, configure it by hand, run it as a systemd service, and watch what it does. Each lesson opens a playground that already has everything from the earlier lessons, so you never rebuild from scratch.

    The control plane runs as systemd services instead of Pods inside Kubernetes. That keeps each component separate from the cluster it builds, which makes it easier to see what each one does.

    The course is for learning, not for production. Some steps use simplified or insecure settings on purpose, and the course points to kubeadm, kops or a managed service for real clusters.

    Kubernetes
    v1.34.0
    containerd
    2.2.1, runc v1.4.0
    CNI plugins
    v1.9.0
    etcd
    v3.6.4
    Flannel
    v0.27.2, CNI plugin v1.7.1-flannel2
    CoreDNS
    1.12.2
    Open lesson 1 on iximiuz Labs
    02Tips and tricksIntroduction

    Every component runs as a systemd service.

    Config files belong to root, so edit them with sudoedit or sudo. The course provides each unit file; it goes in /etc/systemd/system/. After every change to a unit, reload systemd and start the service again.

    When a service does not come up, systemctl status shows its state and journalctl -u shows its logs.

    Open lesson 2 on iximiuz Labs
    Start a service after editing its unit
    $ sudo systemctl daemon-reload
    $ sudo systemctl enable --now kubelet
    CheckRead the logs
    $ sudo journalctl -u kubelet.service
    03containerdWorker node

    One machine that can run containers.

    containerd pulls images and manages containers, but it does not start processes itself. It hands that to an OCI runtime, runc. The lesson installs containerd alone first, and running a container fails until runc is there.

    The next failure is the network: nerdctl asks for the bridge CNI plugin and finds nothing in /opt/cni/bin. After the CNI plugins are installed, a podinfo container starts and answers on port 9898.

    SystemdCgroup = true makes containerd use systemd's cgroup driver. The kubelet is set to the same driver in the next lesson, so both manage one cgroup tree.

    Installs
    containerd 2.2.1, runc v1.4.0, nerdctl 2.2.1, CNI plugins v1.9.0
    Config
    /etc/containerd/config.toml
    Plugins
    /opt/cni/bin
    Open lesson 3 on iximiuz Labs
    BeforeRun a container without runc
    $ sudo ctr run --rm ghcr.io/sagikazarmark/docker-hello-world:latest hello
    ctr: failed to create shim task: OCI runtime create failed:
    unable to retrieve OCI runtime error
    (open /run/containerd/io.containerd.runtime.v2.task/default/hello/log.json: no such file or directory):
    exec: "runc": executable file not found in $PATH
    /etc/containerd/config.toml
    version = 3
    [plugins."io.containerd.cri.v1.runtime".containerd.runtimes.runc.options]
    SystemdCgroup = true
    Checkpodinfo answers
    $ PODINFO_IP=$(sudo nerdctl inspect --format '{{ .NetworkSettings.IPAddress }}' podinfo)
    $ curl -f "http://${PODINFO_IP}:9898"
    04kubeletWorker node

    The kubelet runs Pods before any control plane exists.

    The kubelet reads Pod manifests from /etc/kubernetes/manifests and starts them through containerd. These are static Pods: no API server is involved. Clusters that run their control plane as Pods start it this way.

    Its config is split into small files in /var/lib/kubelet/config.d/, merged in order. For now its API on port 10250 accepts anonymous requests and allows everything. Lesson 9 turns off anonymous access.

    The containers do not show up in nerdctl ps, because Kubernetes puts them in the k8s.io containerd namespace. crictl talks to containerd through the same interface the kubelet uses, so it sees them.

    Installs
    kubelet v1.34.0, crictl v1.34.0, kubeletctl v1.13
    API
    :10250
    Static Pods
    /etc/kubernetes/manifests
    Open lesson 4 on iximiuz Labs
    /var/lib/kubelet/config.d/99-cri.conf
    apiVersion: kubelet.config.k8s.io/v1beta1
    kind: KubeletConfiguration
    containerRuntimeEndpoint: unix:///var/run/containerd/containerd.sock
    cgroupDriver: systemd
    CheckThe static Pod is running
    $ curl -sfk https://localhost:10250/pods | jq '.items[0].metadata'
    05etcdControl plane

    etcd holds all cluster state, and only the API server talks to it.

    The lesson moves to the control-plane machine. etcd starts over plain HTTP so you can write and read keys with etcdctl and see what it stores. Then it gets TLS and requires a client certificate.

    etcd gets its own CA, separate from the Kubernetes one in lesson 6. Only the API server connects to etcd, so this CA signs just two certificates: etcd's server certificate and one client certificate. The course runs a single member and explains why clusters use an odd number of members: a write needs a majority.

    Installs
    etcd, etcdctl, etcdutl v3.6.4
    Port
    :2379 for clients
    Certificates
    /etc/etcd/pki: CA, server, and one client cert shared by etcdctl and the API server
    Open lesson 5 on iximiuz Labs
    Require client certificates
    $ cat <<EOF | sudo tee -a /etc/default/etcd
    ETCD_LISTEN_CLIENT_URLS=https://0.0.0.0:2379
    ETCD_CLIENT_CERT_AUTH=true
    ETCD_CERT_FILE=/etc/etcd/pki/server.crt
    ETCD_KEY_FILE=/etc/etcd/pki/server.key
    ETCD_TRUSTED_CA_FILE=/etc/etcd/pki/ca.crt
    ETCD_NAME=$(hostname)
    ETCD_ADVERTISE_CLIENT_URLS=https://$(hostname):2379
    EOF
    Checketcd is healthy over TLS
    $ bash --login -c "etcdctl endpoint health"
    06kube-apiserverControl plane

    The API server is a REST API in front of etcd.

    A few flags are enough to start it: where etcd is, which certificates to use for it, and the Service range. The lesson creates and patches a namespace with plain curl, then reads the stored object back out of etcd, where it sits under /registry as protobuf.

    Requests need credentials first. The lesson starts with a static token file, then creates the Kubernetes CA and switches to client certificates. The admin certificate has O=system:masters, and RBAC reads that field as the user's group.

    10.96.0.0/12 is the range Service IPs come from. The first address, 10.96.0.1, goes to the kubernetes Service, so it is in the API server certificate's names.

    Installs
    kube-apiserver and kubectl v1.34.0, auger 1.0.3
    Port
    :6443
    Authorization
    Node,RBAC
    Open lesson 6 on iximiuz Labs
    BeforeWithout a token (fails)
    $ curl -f -k https://localhost:6443/api/v1/namespaces
    Flags from the unit file
    --service-cluster-ip-range=10.96.0.0/12 \
        --etcd-cafile=/etc/etcd/pki/ca.crt \
        --etcd-certfile=/etc/etcd/pki/client.crt \
        --etcd-keyfile=/etc/etcd/pki/client.key \
        --etcd-servers=https://127.0.0.1:2379 \
        --authorization-mode=Node,RBAC \
    Checkkubectl reaches the API server
    $ kubectl cluster-info
    07kube-schedulerControl plane

    The scheduler only writes one field.

    Before the scheduler runs, a new Pod stays unscheduled: its spec.nodeName is empty. The lesson creates a Node object by hand, since there is no real worker yet, and then assigns the Pod by posting a Binding with curl.

    That Binding is all the scheduler does. Once it runs, new Pods get a nodeName. They stay Pending, because no kubelet is attached to that Node.

    Installs
    kube-scheduler v1.34.0
    Certificate
    CN=system:kube-scheduler
    Kubeconfig
    /etc/kubernetes/scheduler.conf
    Open lesson 7 on iximiuz Labs
    BeforeNo scheduler: nodeName is empty
    $ kubectl get pod podinfo-unscheduled -o jsonpath='{.spec.nodeName}'
    CheckA new Pod gets a node
    $ kubectl get pod podinfo-scheduler -o jsonpath='{.spec.nodeName}'
    08kube-controller-managerControl plane

    Without controllers, a ReplicaSet creates nothing.

    The API server stores a ReplicaSet with three replicas, and nothing happens. Creating Pods from it is the job of a controller. After kube-controller-manager starts, the three Pods appear, and a deleted Pod is replaced.

    It also hands each node a slice of the Pod network (--allocate-node-cidrs) and signs certificate requests with the Kubernetes CA. Both matter in lessons 9 and 10.

    Installs
    kube-controller-manager v1.34.0
    Pod network
    10.244.0.0/16, one /24 per node
    Certificate
    CN=system:kube-controller-manager
    Open lesson 8 on iximiuz Labs
    BeforeReplicaSet with 3 replicas, no controllers
    $ kubectl get pods -l app=podinfo
    No resources found in default namespace.
    CheckThe ReplicaSet's Pods exist
    $ kubectl get pods -l app=podinfo
    09Joining nodes to the clusterCluster

    The worker asks for its own certificate.

    The worker from lessons 3 and 4 joins the control plane. It only gets the CA certificate and a bootstrap token. The kubelet uses the token once to send a certificate signing request. RBAC approves it automatically, the controller manager signs it, and the kubelet uses the signed certificate from then on.

    The node registers but stays NotReady: the container runtime has no network config. A loopback-only CNI config is enough to make it Ready. Pod networking comes in the next lesson.

    Token
    abcdef.0123456789abcdef, a Secret of type bootstrap.kubernetes.io/token
    Kubelet flags
    --bootstrap-kubeconfig, --kubeconfig
    API server flags
    --enable-bootstrap-token-auth=true, plus a client cert for calling kubelets
    Open lesson 9 on iximiuz Labs
    BeforeThe node registers, but has no network
    $ kubectl describe node worker
    container runtime network not ready: NetworkReady=false reason:NetworkPluginNotReady message:Network plugin returns error: cni plugin not initialized
    The kubelet's bootstrap credentials
    $ sudo kubectl config set-credentials default \
        --kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf \
        --token=abcdef.0123456789abcdef
    CheckThe node is Ready
    $ kubectl wait --for=condition=Ready node worker
    $ kubectl get nodes
    10NetworkCluster

    Pods on two machines can reach each other.

    From here the cluster has two workers, worker-1 and worker-2. A bridge CNI config gives each node's Pods addresses from that node's /24, and Pods on the same node can talk. A Pod on worker-1 cannot reach a Pod on worker-2: neither machine knows where the other's Pod range is.

    The lesson adds the two routes by hand to show that routing is the only missing piece, then removes them and installs Flannel. flanneld runs on each worker, reads the node's Pod range from the API server, and carries traffic between nodes over VXLAN.

    Installs
    flanneld v0.27.2, flannel CNI plugin v1.7.1-flannel2
    Pod ranges
    worker-1 10.244.0.0/24, worker-2 10.244.1.0/24
    Backend
    VXLAN, interface flannel.1
    Open lesson 10 on iximiuz Labs
    BeforeCross-node request, before Flannel (times out)
    $ PODINFO_IP=$(kubectl get pod podinfo-worker-2 -o jsonpath='{.status.podIP}')
    $ kubectl exec client-worker-1 -- curl -fsS --max-time 5 "http://${PODINFO_IP}:9898/version"
    /etc/flannel/net-conf.json
    {
        "Network": "10.244.0.0/16",
        "EnableNFTables": false,
        "Backend": {
            "Type": "vxlan"
        }
    }
    CheckThe same request, with Flannel running
    $ PODINFO_IP=$(kubectl get pod podinfo-worker-2 -o jsonpath='{.status.podIP}')
    $ kubectl exec client-worker-1 -- curl -fsS "http://${PODINFO_IP}:9898/version"
    11kube-proxyCluster

    A Service IP works once kube-proxy writes iptables rules.

    A Service for three podinfo Pods gets a ClusterIP, and its EndpointSlice lists the Pods. A request to the ClusterIP still times out, because no machine has that address. It only exists as a rule.

    kube-proxy runs on each worker and writes those rules. In iptables mode, each Service gets an entry in the KUBE-SERVICES chain that rewrites the destination to one of its Pods, picked at random.

    Installs
    kube-proxy v1.34.0
    Mode
    iptables
    Config
    /etc/kubernetes/kube-proxy/config.yaml, clusterCIDR: 10.244.0.0/16
    Open lesson 11 on iximiuz Labs
    BeforeRequest to the ClusterIP (times out)
    $ CLUSTER_IP=$(kubectl get svc podinfo -o jsonpath='{.spec.clusterIP}')
    $ kubectl exec deploy/podinfo -- curl -fsS --max-time 5 "http://${CLUSTER_IP}:80"
    See the rules it wrote
    $ sudo iptables -t nat -L KUBE-SERVICES -n | grep podinfo
    CheckThe ClusterIP answers
    $ CLUSTER_IP=$(kubectl get svc podinfo -o jsonpath='{.spec.clusterIP}')
    $ kubectl exec deploy/podinfo -- curl -fsS "http://${CLUSTER_IP}:80"
    12CoreDNSCluster

    Service names resolve.

    The lesson first sets the kubelet's clusterDNS to 172.16.0.2, so every new Pod gets it as its nameserver. Nothing answers there yet, so curl http://podinfo fails.

    CoreDNS runs as a systemd service on the control-plane machine and listens on its address, 172.16.0.2, port 53. kubeadm would put it behind a Service at 10.96.0.10; here Pods use the host address directly. CoreDNS watches Services through the API server and answers for cluster.local.

    Installs
    CoreDNS 1.12.2
    Listens on
    172.16.0.2:53, the control-plane's eth0
    Kubelet setting
    clusterDNS: [172.16.0.2], clusterDomain: cluster.local
    Open lesson 12 on iximiuz Labs
    BeforeWhat Pods are told to use
    $ kubectl exec client -- cat /etc/resolv.conf
    search default.svc.cluster.local svc.cluster.local cluster.local
    nameserver 172.16.0.2
    options ndots:5
    CheckThe Service name resolves
    $ kubectl exec client -- curl -fsS --max-time 5 "http://podinfo:80"
    13ConclusionCluster

    What the course leaves out, and what to try next.

    The finished cluster has one control-plane machine, two workers, Flannel, kube-proxy and CoreDNS, all running as systemd services.

    It skips a highly available control plane, backups, tighter security and monitoring. The course suggests building the cluster again from memory, comparing it with what kubeadm generates, and replacing Flannel and kube-proxy with Cilium.

    Its last exercise: stop one component at a time and predict the symptom before you read the logs.

    Open lesson 13 on iximiuz Labs

    How it differs from Kubernetes The Hard Way

    The course says it was inspired by Kelsey Hightower's Kubernetes The Hard Way. Both build a cluster without kubeadm or an installer. They differ in order, in how nodes get their certificates, and in how much of the cluster they cover.

    TopicThe (Very) Hard WayKubernetes The Hard Way
    OrderThe (Very) Hard WayBottom-up: worker node, then control plane, then the cluster that joins themKubernetes The Hard WayTop-down: certificates and kubeconfigs first, then etcd, the control plane and the workers
    MachinesThe (Very) Hard WayOne machine in lessons 3 and 4. control-plane, worker-1 and worker-2 by lesson 10Kubernetes The Hard Wayjumpbox, server, node-0 and node-1 from the first lab
    Where it runsThe (Very) Hard WayBrowser playgrounds on iximiuz Labs, one per lessonKubernetes The Hard WayFour Debian 12 machines you provide
    KubernetesThe (Very) Hard Wayv1.34.0Kubernetes The Hard Wayv1.32.3
    CertificatesThe (Very) Hard WayTwo CAs, one for etcd and one for Kubernetes, each certificate made with openssl when its component is installedKubernetes The Hard WayOne CA and 8 certificates, all made with openssl on the jumpbox in one lab
    Kubelet certificateThe (Very) Hard WayThe kubelet requests it through a CSR, using a bootstrap token. The controller manager signs itKubernetes The Hard WayMade by hand for each node
    Pod networkThe (Very) Hard WayFlannel with VXLAN on 10.244.0.0/16. Static routes are tried first, then removedKubernetes The Hard Waybridge CNI and four static routes on 10.200.0.0/16
    DNSThe (Very) Hard WayCoreDNS on the control-plane hostKubernetes The Hard WayNone
    Secrets at restThe (Very) Hard WayNot encryptedKubernetes The Hard WayEncrypted with aescbc

    What runs where

    Every binary the course downloads, grouped by the machine it runs on. The daemons among them run as systemd services; the rest are command-line tools.

    control-plane

    9binaries
    etcdetcdctletcdutlkube-apiserverkube-schedulerkube-controller-managerkubectlCoreDNSauger

    worker-1 and worker-2

    10binaries
    containerdruncnerdctlCNI pluginskubeletcrictlkubeletctlflanneldflannel CNI pluginkube-proxy