Stage 11, Part 6 of 9, Cluster Lifecycle & Operations

Text

PART 6: HANDS-ON LABS

Lab 1: Plan and Apply a Kubernetes Upgrade

bash
# Check current version
kubectl version --short

# Check upgrade path
sudo kubeadm upgrade plan

# Apply control plane upgrade
sudo kubeadm upgrade apply v1.36.0

# Verify
kubectl get nodes
kubectl get pods -n kube-system

Lab 2: Cordon, Drain, and Uncordon a Node

bash
# Cordon
kubectl cordon <node>

# Drain (with timeout)
kubectl drain <node> --ignore-daemonsets --delete-emptydir-data --timeout=300s

# Verify pods moved
kubectl get pods -o wide

# Uncordon
kubectl uncordon <node>

Lab 3: etcd Snapshot Backup and Restore

bash
# Backup
ETCDCTL_API=3 etcdctl snapshot save /tmp/etcd-backup.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
ETCDCTL_API=3 etcdctl snapshot status /tmp/etcd-backup.db --write-out=table

# Restore (in test environment)
# 1. Stop API server
# 2. Restore snapshot
# 3. Restart API server

Lab 4: Velero Backup and Restore

bash
# Install Velero
velero install --provider aws --bucket velero-backup ...

# Create backup
velero backup create test-backup --include-namespaces default

# Delete namespace
kubectl delete namespace default --force

# Restore
velero restore create --from-backup test-backup

# Verify
kubectl get all

Lab 5: Certificate Rotation

bash
# Check expiry
kubeadm certs check-expiration

# Rotate
sudo kubeadm certs renew all

# Restart kubelet
sudo systemctl restart kubelet

# Verify
kubeadm certs check-expiration

Lab 6: etcd Defragmentation

bash
# Check fragmentation
etcdctl endpoint status --cluster --write-out=table

# Defragment
etcdctl defrag --endpoints=https://etcd-1:2379

# Verify
etcdctl endpoint status --cluster --write-out=table

Lab 7: Cluster API Cluster Provisioning

bash
# Install clusterctl
curl -L https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.12.0/clusterctl-linux-amd64 -o clusterctl
chmod +x clusterctl

# Initialize management cluster
clusterctl init --infrastructure aws

# Generate cluster config
clusterctl generate cluster production --kubernetes-version v1.36.0 > production.yaml

# Apply
kubectl apply -f production.yaml

# Check status
clusterctl describe cluster production

Lab 8: Full Disaster Recovery Drill

bash
# 1. Take etcd snapshot
etcdctl snapshot save /backup/pre-drill.db ...

# 2. Take Velero backup
velero backup create dr-drill --include-namespaces production

# 3. Simulate disaster (delete namespace)
kubectl delete namespace production --force

# 4. Restore from Velero
velero restore create --from-backup dr-drill

# 5. Verify
kubectl get all -n production

# 6. Document RTO

Lab 9: Multi-Cluster Management with Karmada

bash
# Install Karmada
helm repo add karmada https://raw.githubusercontent.com/karmada-io/karmada/master/charts
helm install karmada karmada/karmada -n karmada-system --create-namespace

# Join member clusters
karmadactl join member1 --cluster-kubeconfig=/path/to/member1

# Create PropagationPolicy
cat <<'EOF' | kubectl apply -f -
apiVersion: policy.karmada.io/v1alpha1
kind: PropagationPolicy
metadata:
  name: nginx-propagation
spec:
  resourceSelectors:
  - apiVersion: apps/v1
    kind: Deployment
    name: nginx
  placement:
    clusterAffinity:
      clusterNames:
      - member1
      - member2
EOF

# Deploy workload
kubectl create deployment nginx --image=nginx --replicas=6

1:1 copy of the class Google Doc, code in code blocks.