1. Verify Existing Pods
Begin by checking the current pods in your cluster. Run the following command:2. Review Existing ReplicaSets
Next, inspect if any ReplicaSets are present:3. Analyze ReplicaSet Details
To obtain a detailed description of the ReplicaSet, execute:- Image:
busybox777 - Command:
busybox777.
4. Check Pod Readiness
Examine the number of ready pods in the ReplicaSet. As seen from the detailed description:5. Troubleshoot Pod Readiness Issues
Investigate why the pods are not transitioning to a ready state by describing one of them:ImagePullBackOff. This error occurs because the image busybox777 cannot be pulled, likely due to a non-existent repository or missing authorization.
An excerpt from the pod events:
Kubernetes is unable to pull the image “busybox777” because it either does not exist or you might need to provide proper credentials.
6. Delete a Pod and Observe ReplicaSet Self-Healing
To demonstrate the self-healing nature of ReplicaSets, delete one of the pods. First, list all pods:7. Create a ReplicaSet Using a Definition File
Now, learn how to create a ReplicaSet from a YAML definition file. First, confirm the existence of the file:ReplicaSet definition.yaml, attempt to create the ReplicaSet:
apps/v1.
Use the command
kubectl explain replicaset to verify the correct API version.8. Correct a Second ReplicaSet Definition File
Attempt to create a second ReplicaSet using another definition file:spec.selector.matchLabels and template.metadata.labels sections. They must match exactly. For example:
9. Update the Original ReplicaSet Image
The original ReplicaSet is still configured to usebusybox777. To update the image to busybox, edit the ReplicaSet:
10. Scaling the ReplicaSet
Scale Up to 5 Pods
Increase the ReplicaSet to five pods with the scale command:Scale Down to 2 Pods
To reduce the number of pods to two, edit the ReplicaSet:spec.replicas field to 2 and save the file. The ReplicaSet will automatically adjust the pod count accordingly.
This concludes the ReplicaSets lab. In the next lesson, we will explore Deployments and demonstrate how they extend the concepts introduced by ReplicaSets. For more details on Kubernetes concepts, visit the Kubernetes Documentation.