AlgoViz

Kubernetes

medium 34 min

Kubernetes runs containers on many machines.

See it run

Follow one plan from the API server to running pods, then break things and watch the loops repair them.

Operations

Apply to running

One Deployment becomes three running pods. Every part only watches and writes objects.

Step 1 of 6

Send the plan

ClusterkubectlControllersAPI serverfront doorScheduleretcdall statekubeletnode agentPodsnone

Desired

api: 3 pods

kubectl apply sends a Deployment with three replicas. The API server checks who you are, what you may do, admission rules and the schema.

Step 1: Send the plan

def reconcile():    want = desired.replicas    have = len(matching_pods())    if have < want:        create(want - have)      # Pod objects, no node yet    elif have > want:        delete(have - want)def schedule(pod):    fits = [n for n in nodes if room(n, pod.requests)]    pod.node = max(fits, key=score)   # kubelet does the rest
Time
seconds
What you need
image, requests

Say that the scheduler only writes a node name. Many people think it starts containers.

In the real world

The same kubernetes doing real jobs. Pick one and step through it.

Version 2 crashes on start. See what the platform does and does not do.

Step 1 of 4

Release

ClusterUsersServicestable addressPod 1v1 readyPod 2v1 readyPod 3v1 readyPod 4v2 starting

v2 starts beside three v1 pods.

Step 1: Release

Common mistakes

The bugs interviewers watch for, with the fix beside each.

  • Liveness probe that tests the database

    critical

    A slow database fails the probe on every pod, and all of them restart together.

    Wrong
    livenessProbe:  httpGet: { path: /health-with-db, port: 3000 }
    Right
    livenessProbe:  httpGet: { path: /live, port: 3000 }   # process onlyreadinessProbe:  httpGet: { path: /ready, port: 3000 }
  • No resource requests

    major

    The scheduler packs blindly and the HPA cannot compute a percentage.

    Wrong
    resources: {}
    Right
    resources:  requests: { cpu: 100m, memory: 256Mi }  limits: { memory: 512Mi }
  • Trusting automatic rollback

    major

    A failed rollout only stalls and reports a condition.

    Wrong
    kubectl apply -f v2.yaml   # and go home
    Right
    kubectl apply -f v2.yamlkubectl rollout status deploy/api --timeout=10m \  || kubectl rollout undo deploy/api
  • Pod addresses in configuration

    critical

    Pods are replaced and get new addresses.

    Wrong
    API_URL=http://10.244.1.5:3000
    Right
    API_URL=http://api

Interview tips

  • How to explain it

    • Desired state in etcd.
    • Loops observe, compare, act.
    • Scheduler chooses, kubelet starts.
  • Memory trick

    • The plan is on the shed door.
    • Ready is traffic, live is restart.
    • Requests place, limits cap.
  • Reach for it when

    • Many services and teams.
    • Releases all day.
    • Failures must heal without people.
  • Be careful with

    • Databases inside the cluster.
    • One service and a small team.
    • Secrets and network: open until you act.