Kubernetes Administration — Level by Level›Level 2 · Cheat sheet & self-check

Level 2 — Operator · wrap-up

Cheat sheet & self-check

Every command from this section on one page.

09 · Build a cluster with kubeadm

Node preparation

sudo swapoff -aDisable swap now (also remove it from /etc/fstab)
sudo modprobe overlay && sudo modprobe br_netfilterKernel modules containers and bridged traffic need
containerd config default | sudo tee /etc/containerd/config.tomlWrite a default containerd config (then set SystemdCgroup = true)
sudo apt-mark hold kubelet kubeadm kubectlStop unattended upgrades changing versions

Build the cluster

sudo kubeadm init --control-plane-endpoint <LB-or-DNS>:6443 --pod-network-cidr 10.244.0.0/16 --upload-certsFirst control-plane node
kubeadm token create --print-join-commandNew worker join command (tokens expire after 24h)
sudo kubeadm join <endpoint>:6443 --token … --discovery-token-ca-cert-hash sha256:…Join a worker
sudo kubeadm resetUndo init/join on a node (then clean CNI config and iptables)

Certificates

sudo kubeadm certs check-expirationWhen each certificate expires
sudo kubeadm certs renew allRenew all kubeadm-managed certificates
ls /etc/kubernetes/pkiWhere the cluster PKI lives

10 · kubeadm at scale: immutable images

Image & boot

Base image: OS + containerd + kubelet/kubeadm/kubectl (pinned) + kernel settingsEverything that's the same on every node
Role at boot: cloud-init user-data (init / join / join --control-plane)One image, many roles
DHCP reservation (MAC → IP) or static network-configPredictable node IPs
cloud-init clean && truncate -s0 /etc/machine-idMake a template clonable (no duplicate identities)

kubeadm automation

kubeadm token generateCreate a bootstrap token value in advance
kubeadm init --config init.yaml --upload-certsFirst control plane from a config file
kubeadm init phase upload-certs --upload-certsRe-upload certs for control-plane joins (the key expires after 2 h)
kubeadm join --config join.yamlJoin as worker or control plane from a config file
openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hexCompute the CA cert hash for discovery

11 · Bare-metal load balancing with MetalLB

Install & configure

helm repo add metallb https://metallb.github.io/metallb && helm install metallb metallb/metallb -n metallb-system --create-namespaceInstall MetalLB
IPAddressPool (spec.addresses: [10.0.0.240-10.0.0.250])Which IPs MetalLB may hand out
L2Advertisement (spec.ipAddressPools: [...])Announce those IPs with ARP/NDP
BGPPeer + BGPAdvertisementAnnounce them to routers with BGP

Check

kubectl get svc -A | grep LoadBalancerEXTERNAL-IP assigned?
kubectl get ipaddresspools,l2advertisements,bgppeers -n metallb-systemMetalLB config
kubectl logs -n metallb-system -l app.kubernetes.io/component=speakerWhich node announces what
arping -I eth0 10.0.0.240 (from another host on the segment)Who answers ARP for the VIP

12 · Upgrades & version skew

Before you start

kubectl versionCurrent client and server versions
kubectl get nodesEvery node's kubelet version
sudo kubeadm upgrade planWhat you can upgrade to, component by component
kubectl get pdb -APodDisruptionBudgets that could block drains

Control plane (first node)

sudo apt-mark unhold kubeadm && sudo apt-get install -y kubeadm='1.32.x-*' && sudo apt-mark hold kubeadmUpgrade the kubeadm binary first
sudo kubeadm upgrade apply v1.32.xUpgrade control-plane components (first control-plane node only)
sudo kubeadm upgrade nodeOther control-plane nodes, and every worker

Each node's kubelet

kubectl drain <node> --ignore-daemonsets --delete-emptydir-dataMove workloads off safely
sudo apt-get install -y kubelet='1.32.x-*' kubectl='1.32.x-*'Upgrade kubelet and kubectl (unhold/hold around it)
sudo systemctl daemon-reload && sudo systemctl restart kubeletRestart with the new version
kubectl uncordon <node>Allow scheduling again

13 · etcd backup & restore

Take and check a snapshot

ETCDCTL_API=3 etcdctl --endpoints=https://127.0.0.1:2379 --cacert=/etc/kubernetes/pki/etcd/ca.crt --cert=/etc/kubernetes/pki/etcd/server.crt --key=/etc/kubernetes/pki/etcd/server.key snapshot save /backup/etcd.dbSave a snapshot (kubeadm certificate paths)
etcdutl snapshot status /backup/etcd.db -w tableHash, revision, key count, size
etcdctl … endpoint status -w tableLeader, DB size, raft term per member
etcdctl … member list -w tableMembers of the etcd cluster

Restore (single control plane, kubeadm)

sudo mv /etc/kubernetes/manifests/kube-apiserver.yaml /root/Stop the API server (no writes during restore)
sudo etcdutl snapshot restore /backup/etcd.db --data-dir /var/lib/etcd-restoredRestore into a NEW data directory
sudo vi /etc/kubernetes/manifests/etcd.yamlPoint the etcd-data hostPath at /var/lib/etcd-restored
sudo mv /root/kube-apiserver.yaml /etc/kubernetes/manifests/Start the API server again

14 · Scheduling in depth

Labels & taints

kubectl label node w1 disktype=ssdAdd a node label
kubectl get nodes -L disktype,topology.kubernetes.io/zoneShow labels as columns
kubectl taint node w1 dedicated=gpu:NoScheduleRepel pods without a matching toleration
kubectl taint node w1 dedicated=gpu:NoSchedule-Remove that taint (trailing minus)
kubectl describe node w1 | grep -A3 TaintsSee a node's taints

Why is it Pending?

kubectl describe pod <pod>The FailedScheduling event lists each reason
kubectl get events --field-selector reason=FailedSchedulingAll scheduling failures
kubectl describe node <node> | grep -A8 'Allocated resources'How much CPU/memory is already requested

Priority

kubectl get priorityclassAvailable priorities (system-cluster-critical, …)

15 · RBAC & service accounts

Check permissions

kubectl auth can-i create deployments -n shopCan I do this?
kubectl auth can-i --list -n shopEverything I can do in a namespace
kubectl auth can-i get secrets -n shop --as=system:serviceaccount:shop:appTest as a service account
kubectl auth whoamiWho does the API server think I am?

Create RBAC quickly

kubectl create role pod-reader --verb=get,list,watch --resource=pods -n shopA namespaced Role
kubectl create rolebinding read-pods --role=pod-reader --user=asha -n shopBind it to a user
kubectl create clusterrolebinding ops-view --clusterrole=view --group=opsBuilt-in read-only role, cluster-wide, for a group
kubectl create serviceaccount app -n shopAn identity for a workload
kubectl create token app -n shop --duration=1hA short-lived token for that service account

Inspect

kubectl get roles,rolebindings -n shopNamespaced RBAC objects
kubectl describe clusterrole editWhat a built-in role allows

16 · Troubleshooting: nodes, pods, networking

Scope it

kubectl get nodesIs it one node or all of them?
kubectl get pods -A -o wide | grep -v RunningEverything not Running, and where
kubectl get events -A --sort-by=.lastTimestamp | tail -30What happened most recently

Pods

kubectl describe pod <pod>Events, state, last state, exit code
kubectl logs <pod> --previousLogs from the crashed container
kubectl debug -it <pod> --image=busybox:1.36 --target=<container>Ephemeral debug container sharing the pod's namespaces
kubectl get pod <pod> -o jsonpath='{.status.containerStatuses[*].lastState}'Why the last run ended

Nodes

kubectl describe node <node>Conditions: Ready, MemoryPressure, DiskPressure, PIDPressure
kubectl debug node/<node> -it --image=busybox:1.36Shell on the node (host filesystem at /host)
systemctl status kubelet containerdAre the node agents running? (on the node)
journalctl -u kubelet --since '15 min ago'Why the kubelet is unhappy (on the node)
crictl ps -aContainers the runtime knows about, even if the API is down