Kubernetes Controllers
Objective
This lab will help you understand the role of Kubernetes controllers in managing the desired/actual state of cluster resources.
Prerequisites
- A Kubernetes cluster (Minikube, Kind, or a cloud-based Kubernetes cluster)
 kubectlinstalled and configured
Step 1: Understand Controllers
Kubernetes controllers are control loops that monitor the state of the cluster and make or request changes where needed. The key controllers include:
- Deployment Controller (manages ReplicaSets for stateless applications)
 - ReplicaSet Controller (ensures a specified number of pod replicas)
 - StatefulSet Controller (manages stateful applications)
 - DaemonSet Controller (ensures a copy of a pod runs on each node)
 - Job Controller (runs batch jobs to completion)
 - CronJob Controller (manages periodic tasks)
 
Step 2: Create a ReplicaSet
A ReplicaSet ensures a specified number of pod replicas run at all times.
Verify the ReplicaSet.
Delete a pod and observe self-healing.
Check the ReplicaSet description to see controller activity.
Observe Pod Events for the current namespace.
View logs related to the ReplicaSet controller, and extract the one related to <my-namespace>/my-replicaset.
You should see that Kubernetes automatically creates a new pod to maintain the desired state.
Step 3: Scale the ReplicaSet
Scale the ReplicaSet to 5 replicas:
kubectl scale replicaset my-replicaset --replicas=5Check the number of pods:
kubectl get podsStep 4: Cleanup
Delete the ReplicaSet:
kubectl delete replicaset my-replicasetVerify resources are removed:
kubectl get allConclusion
You have successfully learned how Kubernetes controllers maintain the desired state of your applications. Explore other controllers like StatefulSet, DaemonSet, and Jobs to deepen your understanding!