Kubernetes
medium 34 minKubernetes 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
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
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
criticalA slow database fails the probe on every pod, and all of them restart together.
WronglivenessProbe: httpGet: { path: /health-with-db, port: 3000 }RightlivenessProbe: httpGet: { path: /live, port: 3000 } # process onlyreadinessProbe: httpGet: { path: /ready, port: 3000 }No resource requests
majorThe scheduler packs blindly and the HPA cannot compute a percentage.
Wrongresources: {}Rightresources: requests: { cpu: 100m, memory: 256Mi } limits: { memory: 512Mi }Trusting automatic rollback
majorA failed rollout only stalls and reports a condition.
Wrongkubectl apply -f v2.yaml # and go homeRightkubectl apply -f v2.yamlkubectl rollout status deploy/api --timeout=10m \ || kubectl rollout undo deploy/apiPod addresses in configuration
criticalPods are replaced and get new addresses.
WrongAPI_URL=http://10.244.1.5:3000RightAPI_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.