PART 2: ADVANCED CONCEPTS
6. Velero
Velero (formerly Heptio Ark) is the de-facto standard for Kubernetes workload backup and restore. It backs up Kubernetes objects and persistent volume data, and restores them to the same or a different cluster.
What Velero Backs Up
| Component | Method |
| Kubernetes objects | API server export |
| Persistent volumes | CSI snapshots or file-system backup |
| CRDs | API server export |
| Namespaces | Selective backup |
| Secrets | Encrypted storage |
Velero Architecture
text
Velero CLI → Velero Server (in-cluster) → Object Storage (S3, GCS, Azure Blob)
│
├── Node Agent (DaemonSet) → PV data
└── CSI Snapshotter → Volume snapshots
Installing Velero
bash
velero install \
--provider aws \
--plugins velero/velero-plugin-for-aws:v1.14.0 \
--bucket my-velero-backups \
--backup-location-config region=us-east-1 \
--snapshot-location-config region=us-east-1 \
--secret-file ./credentials-velero
Backup and Restore
bash
# Create a backup
velero backup create production-backup --include-namespaces production
# Check status
velero backup describe production-backup
velero backup logs production-backup
# Restore
velero restore create --from-backup production-backup
# Schedule backups
velero schedule create daily-backup \
--schedule="0 2 * * *" \
--include-namespaces production \
--ttl 168h # 7-day retention
Velero Best Practices
| Practice | Why |
| Use schedules, not manual backups | Consistency |
| Set appropriate TTL | Cost control (7–30 days typical) |
| Verify backup content | Check datauploads, not just Completed status |
| Test restores regularly | Backups without restores are useless |
| Store offsite | Protect against site failure |
| Encrypt backups | Security |
The Critical Distinction: etcd vs Velero
The etcd snapshot is your control-plane insurance. Velero is your workload insurance and your only way to restore selectively or into a new cluster.
7. etcd Compaction and Defragmentation
Why etcd Grows
etcd's database file grows over time even when you're not adding objects. Compaction removes old revisions logically, but the bbolt backend does not shrink the file on disk. Without defragmentation, the file grows indefinitely.
The Two Operations
| Operation | What It Does |
| Compaction | Removes old revisions from the logical keyspace |
| Defragmentation | Reclaims disk space by removing gaps from deleted keys |
Automatic Compaction
The Kubernetes API server passes --etcd-compaction-interval to trigger compaction periodically.
Manual Defragmentation
bash
# Check fragmentation
etcdctl endpoint status --cluster --write-out=table
# Defragment one member at a time
etcdctl defrag --endpoints=https://etcd-1:2379
# Verify
etcdctl endpoint status --cluster --write-out=table
Warning: Defragmentation blocks the etcd member for the duration. Do one member at a time, never all at once.
etcd-defrag Tool
The community maintains etcd-defrag, a smarter defragmentation tool that:
- Checks health of all members before starting
- Defragments the leader last
- Supports rule-based defragmentation
- Auto-disarms NOSPACE alarms
Monitoring etcd Size
bash
# Database size
etcdctl endpoint status --write-out=table
# Alarm if DB size > 2 GB (default quota is 2 GB)
etcdctl alarm list
Production rule: Alert when etcd DB size exceeds 1.5 GB. Defragment proactively.
8. Certificate Rotation
Kubernetes uses TLS certificates for all control plane communication. These certificates expire, and if they do, the cluster breaks.
Certificate Types and Validity
| Certificate | Default Validity |
| kube-apiserver serving cert | 1 year |
| kube-apiserver client cert | 1 year |
| etcd serving cert | 1 year |
| etcd peer cert | 1 year |
| kubelet client cert | 1 year |
| kubelet serving cert | 1 year |
| CA certificate | 10 years |
Rotation Methods
| Method | Description |
| kubeadm | kubeadm certs renew all |
| Managed services | Automatic (EKS, AKS, GKE) |
| Rancher | rke certificate rotate |
| Manual | Regenerate and replace |
kubeadm Certificate Rotation
bash
# Check expiry
kubeadm certs check-expiration
# Rotate all
sudo kubeadm certs renew all
# Restart control plane components
sudo systemctl restart kubelet
Managed Service CA Rotation (2026)
Amazon EKS now supports certificate authority (CA) rotation with automated lifecycle management, enabling customers to rotate their cluster's CA through a managed lifecycle with automated safeguards.
Certificate Rotation Best Practices
| Practice | Why |
| Rotate before expiry | Avoid cluster outage |
| Plan a maintenance window | Control plane briefly unavailable |
| Back up certificates | Rollback safety |
| Test in staging | Verify procedure |
| Automate with managed services | Reduce operational burden |
9. Cluster API (CAPI)
Cluster API (CAPI) is a Kubernetes sub-project that lets you manage the lifecycle of Kubernetes clusters using Kubernetes itself. You define a cluster in YAML, apply it to a management cluster, and CAPI controllers provision the infrastructure, bootstrap the nodes, and install Kubernetes.
CAPI Architecture
text
┌─────────────────────────────────────────────────────────────┐
│ CLUSTER API ARCHITECTURE │
│ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Management Cluster (runs CAPI controllers) │ │
│ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │
│ │ │ CAPI Core │ │ Infra │ │ Bootstrap │ │ │
│ │ │ Controllers │ │ Provider │ │ Provider │ │ │
│ │ └─────────────┘ └─────────────┘ └─────────────┘ │ │
│ └─────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Workload Clusters │ │
│ │ • Cluster 1 (AWS) │ │
│ │ • Cluster 2 (vSphere) │ │
│ │ • Cluster 3 (bare metal) │ │
│ └─────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
The Four Layers
| Layer | Purpose | Examples |
| Core | Cluster and Machine abstractions | Cluster, Machine, MachineSet |
| Infrastructure | Cloud resource provisioning | AWSCluster, VSphereCluster |
| Bootstrap | Turn machine into K8s node | KubeadmConfig, TalosConfig |
| Control Plane | Manage control plane | KubeadmControlPlane |
CAPI v1.12 (January 2026)
The v1.12 release introduced in-place updates and chained upgrades:
- In-place updates allow users to make changes on existing machines without delete-and-recreate
- Chained upgrades allow clusters using managed topologies to upgrade by more than one minor Kubernetes version through efficient sequential upgrades
CAPI Cluster Definition
yaml
apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
metadata:
name: production
spec:
clusterNetwork:
pods:
cidrBlocks: ["192.168.0.0/16"]
controlPlaneRef:
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
kind: KubeadmControlPlane
name: production-control-plane
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: AWSCluster
name: production
CAPI Strengths
| Strength | Why |
| Consistency | Same API across clouds |
| GitOps compatibility | YAML in version control |
| Automated upgrades | CAPI sequences control plane upgrades |
| Multi-cloud | 37+ infrastructure providers |
When to Use CAPI
| Scenario | CAPI? |
| Multi-cloud fleet | ✅ Yes |
| On-prem + cloud | ✅ Yes |
| Single managed cluster | ❌ Use managed service |
| Small team | ❌ Use managed service |
CAPI standardizes how clusters are created and managed, but it does little to improve how clusters behave in production or reduce operational friction for SREs. Use it when fleet consistency matters more than simplicity.
10. Multi-Cluster Management
Karmada
Karmada (Kubernetes Armada) is a CNCF-graduated project for multi-cluster, multi-cloud Kubernetes orchestration. It extends the standard Kubernetes API with centralized placement, propagation, failover, and multi-cluster autoscaling.
Karmada Architecture
| Component | Purpose |
| Karmada Control Plane | Central API, scheduler, controllers |
| Member Clusters | Workload clusters (push or pull mode) |
| ResourceBinding | Workload distribution decisions |
| PropagationPolicy | Where workloads should run |
Karmada v1.19 (2026)
The v1.19 release advances multi-component scheduling for distributed AI training jobs and promotes priority-based scheduling to Beta, enabled by default.
Karmada Use Cases
| Use Case | Description |
| Hybrid cloud | Run workloads across AWS, GCP, on-prem |
| Multi-region | Distribute workloads globally |
| AI/ML training | Schedule across GPU clusters |
| Disaster recovery | Active-active multi-cluster |
Fleet (Rancher)
Fleet is Rancher's multi-cluster management tool. It deploys applications across clusters with GitOps.
Comparison
| Tool | Approach | CNCF Status |
| Karmada | Central control plane, propagation policies | Graduated |
| Fleet | GitOps-driven, Rancher-native | Incubating |
| Cluster API | Declarative cluster provisioning | Production-ready |
| vCluster | Virtual clusters | CNCF sandbox |
11. Node Problem Detector
Node Problem Detector (NPD) is a DaemonSet that runs on every node. It monitors system logs, runs custom checks, and reports problems as node conditions or events that Kubernetes and operators can act upon.
What NPD Detects
| Problem Type | Example |
| Kernel deadlocks | Hung tasks, soft lockups |
| Hardware failures | Disk errors, memory errors |
| Network problems | NIC down, packet loss |
| Resource pressure | Disk, memory, PID pressure |
NPD Architecture
text
NPD DaemonSet (per node)
│
├── system-log-monitor (kernel logs)
├── custom-plugin-monitor (custom checks)
└── kernel-monitor (kernel events)
│
▼
API Server (NodeCondition + Events)
│
▼
Scheduler / Autoscaler / Operators
Deploying NPD
yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: node-problem-detector
namespace: kube-system
spec:
selector:
matchLabels:
app: node-problem-detector
template:
metadata:
labels:
app: node-problem-detector
spec:
hostNetwork: true
containers:
- name: node-problem-detector
image: registry.k8s.io/node-problem-detector/node-problem-detector:v0.8.19
securityContext:
privileged: true
volumeMounts:
- name: log
mountPath: /var/log
readOnly: true
12. Disaster Recovery Strategy
RTO and RPO
| Metric | Definition | Depends On |
| RTO (Recovery Time Objective) | Maximum acceptable downtime | Recovery speed |
| RPO (Recovery Point Objective) | Maximum acceptable data loss | Backup frequency |
The Four Recovery Layers
For a recovery to count, four layers must come back:
- Cluster infrastructure (nodes, networking)
- Cluster state (etcd / API objects)
- Persistent data (volumes)
- Traffic path (DNS, ingress, load balancers)
Recovery fails at the joins between the layers: a restored cluster with no data, restored data with no traffic path, an application definition that provisions an empty volume.
DR Strategy Matrix
| Strategy | RPO | RTO | Cost |
| Backup/Restore | Hours | Hours | $ |
| Snapshot | Minutes | Minutes | $$ |
| Replication | Seconds | Minutes | $$$ |
| Active-Active | Zero | Zero | $$$$ |
DR Testing
| Test | Frequency |
| Restore etcd snapshot | Monthly |
| Restore from Velero | Monthly |
| Full cluster rebuild | Quarterly |
| Multi-region failover | Quarterly |
13. Infrastructure as Code for Clusters
Terraform for Cluster Provisioning
hcl
resource "aws_eks_cluster" "production" {
name = "production"
role_arn = aws_iam_role.eks.arn
version = "1.36"
vpc_config {
subnet_ids = aws_subnet.private[*].id
}
}
resource "aws_eks_node_group" "workers" {
cluster_name = aws_eks_cluster.production.name
node_group_name = "workers"
node_role_arn = aws_iam_role.nodes.arn
subnet_ids = aws_subnet.private[*].id
instance_types = ["m5.xlarge"]
scaling_config {
desired_size = 3
max_size = 10
min_size = 1
}
}
Crossplane for Kubernetes-Native Infrastructure
Crossplane extends Kubernetes to manage cloud resources as CRDs. Instead of Terraform, you define cloud resources as Kubernetes objects.
yaml
apiVersion: rds.aws.upbound.io/v1beta1
kind: Instance
metadata:
name: production-db
spec:
forProvider:
region: us-east-1
instanceClass: db.t3.medium
engine: postgres
allocatedStorage: 100
1:1 copy of the class Google Doc, code in code blocks.