PART 1: CORE THEORY
1. The Cluster Lifecycle
A Kubernetes cluster is not a static artifact. It has a lifecycle: provision, operate, upgrade, scale, and eventually retire. Every phase must be planned, automated, and tested.
The Five Phases
| Phase | Activities | Tools |
| Provisioning | Create control plane, join nodes, install CNI/CSI | kubeadm, Cluster API, managed services |
| Operations | Monitor, scale, back up, rotate certs | Prometheus, Velero, cert-manager |
| Upgrades | Control plane, then workers, then validation | kubeadm, Cluster API |
| Disaster Recovery | Restore from etcd snapshot or Velero backup | etcdctl, Velero |
| Retirement | Drain nodes, delete cluster, clean up cloud resources | kubectl, Terraform |
Why Lifecycle Management Matters
A poorly prepared update represents a significant portion of cluster incidents. IT teams spend an average of 34 working days per year resolving Kubernetes issues, and a large share comes from unplanned upgrade problems.
2. Kubernetes Version Skew Policy
The version skew policy defines which combinations of component versions are supported. Violating it causes subtle failures that are hard to diagnose.
Supported Versions
The Kubernetes project maintains release branches for the most recent three minor releases (e.g., 1.37, 1.36, 1.35). Kubernetes 1.19 and newer receive approximately 1 year of patch support.
Version Skew Rules
| Component | Rule |
| kube-apiserver (HA) | Newest and oldest instances must be within one minor version |
| kubelet | Must not be newer than apiserver; may be up to three minor versions older |
| kube-proxy | Must not be newer than apiserver; may be up to three minor versions older |
| kubectl | Within one minor version of apiserver (older or newer) |
Example: HA Cluster with Version Skew
text
kube-apiserver instances: 1.37 and 1.36
kubelet supported: 1.36, 1.35, 1.34
Note: 1.37 is NOT supported because that would be newer than the 1.36 apiserver instance[reference:2]
The Golden Rule
Never more than one minor version difference between components during an upgrade. Upgrade control plane first, then workers one by one.
3. Cluster Upgrades
Kubernetes upgrades follow a strict control plane first, then workers one by one sequence.
The Three Phases
text
Phase 1: Control Plane Upgrade
│
├── Upgrade API server
├── Upgrade controller manager
├── Upgrade scheduler
└── Upgrade etcd
│
▼
Phase 2: Worker Node Upgrade (one at a time)
│
├── Cordon node
├── Drain node (evict pods)
├── Upgrade kubelet and kube-proxy
├── Uncordon node
└── Repeat for each node
│
▼
Phase 3: Validation
│
├── Check node status
├── Verify workloads
└── Monitor for issues
Pre-Upgrade Checklist
| Step | Command |
| Check current version | kubectl version --short |
| Check target version | kubeadm upgrade plan |
| Audit deprecated APIs | kubectl get --raw /metrics | grep apiserver_requested_deprecated_apis |
| Back up etcd | etcdctl snapshot save |
| Check PDBs | kubectl get pdb -A |
| Verify node health | kubectl get nodes |
kubeadm Upgrade Commands
bash
# On control plane node
sudo kubeadm upgrade plan
sudo kubeadm upgrade apply v1.36.0
# On other control plane nodes
sudo kubeadm upgrade node
# On worker nodes (one at a time)
kubectl cordon <node>
kubectl drain <node> --ignore-daemonsets --delete-emptydir-data
sudo kubeadm upgrade node
kubectl uncordon <node>
Upgrade Timeline
| Cluster Size | Expected Time |
| 3 nodes | 30–60 minutes |
| 10 nodes | 2–4 hours |
| 50 nodes | 8–12 hours |
| 100+ nodes | 1–2 days |
4. Node Lifecycle Management
Node lifecycle operations are the foundation of cluster maintenance.
Cordon
Cordon marks a node as unschedulable. Existing Pods continue running, but new Pods won't be scheduled.
bash
kubectl cordon <node>
Drain
Drain evicts all Pods from a node (except DaemonSets) and marks it unschedulable.
bash
kubectl drain <node> --ignore-daemonsets --delete-emptydir-data
Options:
| Flag | Purpose |
--ignore-daemonsets | Skip DaemonSet Pods (they can't be evicted) |
--delete-emptydir-data | Delete Pods using emptyDir |
--force | Force deletion of Pods not managed by controllers |
--grace-period | Override default grace period |
--timeout | Timeout for the drain |
Uncordon
Uncordon makes the node schedulable again.
bash
kubectl uncordon <node>
PodDisruptionBudgets and Drain
PDBs protect applications during voluntary disruptions. A PDB defines how many pods must remain available during a drain. Without PDBs, a node drain can take your entire service offline if all replicas are on one node.
Common PDB mistakes:
| Mistake | Impact |
| Never allow disruptionsAllowed to equal 0 in steady state | Drain stalls forever |
| Using PDBs for single-replica deployments | Drain blocks |
| Scope PDB selector too broadly | Unexpected protection |
| Not setting PDBs at all | Service outage during drain |
Graceful Node Shutdown
Kubernetes supports graceful node shutdown — when the OS signals shutdown, kubelet terminates Pods gracefully.
yaml
# /var/lib/kubelet/config.yaml
shutdownGracePeriod: 30s
shutdownGracePeriodCriticalPods: 10s
5. etcd Backup and Restore
etcd stores 100% of Kubernetes cluster state — namespaces, deployments, services, RBAC, CRDs, secrets. Without a functional etcd backup, corruption or data loss means complete cluster reconstruction.
Manual Snapshot
bash
export ETCDCTL_API=3
etcdctl snapshot save /backup/etcd-$(date +%Y%m%d-%H%M%S).db \
--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
# Verify integrity
etcdctl snapshot status /backup/etcd-20260228-143000.db --write-out=table
Automated etcd Backup (CronJob)
yaml
apiVersion: batch/v1
kind: CronJob
metadata:
name: etcd-backup
namespace: kube-system
spec:
schedule: "0 */6 * * *" # Every 6 hours
jobTemplate:
spec:
template:
spec:
hostNetwork: true
containers:
- name: backup
image: registry.k8s.io/etcd:3.5.12-0
command:
- /bin/sh
- -c
- |
etcdctl snapshot save /backup/etcd-$(date +%Y%m%d-%H%M%S).db
find /backup -mtime +7 -delete
env:
- name: ETCDCTL_API
value: "3"
volumeMounts:
- name: etcd-certs
mountPath: /etc/kubernetes/pki/etcd
readOnly: true
- name: backup
mountPath: /backup
Restore Procedure
- Stop the API server (move static pod manifests)
- Remove old etcd data from
/var/lib/etcd - Restore the snapshot with
etcdutl snapshot restore - Restore static pod manifests
- Restart kubelet
- Verify cluster health
Critical: Test restores in staging before production. The etcd snapshot restore process modifies cluster identifiers.
1:1 copy of the class Google Doc, code in code blocks.