Skip to main content
In this guide, we review the ReplicaSets lab exercise by detailing each command, expected output, and the rationale behind every step. Follow along to understand how to diagnose issues, update configurations, and scale your ReplicaSet efficiently.

Checking the Initial State

Before proceeding, verify there are no existing Pods or ReplicaSets in your cluster.
  1. List all Pods:
    Expected output:
    This confirms that there are currently zero Pods running.
  2. List any existing ReplicaSets:
    The command similarly shows no ReplicaSets at this point.

Verifying the New ReplicaSet

After applying some changes, a new ReplicaSet is created. Confirm its presence using:
The output should display something similar to:
This indicates that the new ReplicaSet is configured to have 4 Pods. Running the command a second time reaffirms the same output.

Determining the Image Used by the ReplicaSet

To inspect the details of the ReplicaSet and determine which image is assigned to its Pods, execute:
Within the Pod Template section under Containers, look for the image field:
Also, the command section appears as:
This verifies that the ReplicaSet is initially using the image “busybox777”.

Examining the Pod Readiness Issue

If the Pods are not transitioning to the Ready state, further investigation is required:
  1. Check the replica status:
    You should see an excerpt like:
  2. Inspect one of the Pods to identify the issue:
    Notice the container is in a Waiting state with the reason:
    And an associated event message:
The error indicates that there is no image named “busybox777” available in the repository. Use the standard BusyBox image instead.

Deleting a Pod Managed by the ReplicaSet

ReplicaSets are designed to maintain the desired number of Pods automatically. Even if you delete a Pod, the ReplicaSet immediately replicates a new one.
  1. List the Pods:
    Example output:
  2. Delete one of the Pods:
    Confirmation output:
  3. List the Pods again to note that the ReplicaSet has recreated the missing Pod.

Creating ReplicaSets Using YAML Definition Files

Two YAML definition files are located in the /root directory:
  • replicaset-definition-1.yaml
  • replicaset-definition-2.yaml

Fixing the First Definition File

The initial content of replicaset-definition-1.yaml is:
When running:
you encounter the error:
Inspecting the available API versions with:
reveals that the correct API version is apps/v1. Update the file accordingly. After the change, creation should succeed.

Fixing the Second Definition File

The content of replicaset-definition-2.yaml is:
Creating it results in the error:
This occurs because the selector (tier: frontend) does not match the Pod template labels (tier: nginx). Correct the Pod template labels to use tier: frontend so they match the selector. After this fix, create the ReplicaSet again using:
The ReplicaSet “replicaset-2” should now be successfully created.

Deleting Newly Created ReplicaSets

After verification, remove replicaset-1 and replicaset-2 from your cluster.
  1. List the current ReplicaSets to check their status:
    Example output:
  2. Delete the ReplicaSets:
Confirmation messages will indicate that both ReplicaSets have been removed.

Updating the Original ReplicaSet’s Image

Since the original ReplicaSet (“new-replica-set”) uses an incorrect image (“busybox777”), update it to use the proper BusyBox image.
  1. Edit the ReplicaSet:
    Locate the container section and update the image field:
  2. Save the changes and verify by describing the ReplicaSet:
Despite the update, existing Pods may still reflect the previous error because updating the ReplicaSet does not restart the existing Pods. To resolve this issue, manually delete the problematic Pods so that the ReplicaSet creates new ones with the corrected image:
After a short wait, list the Pods again:
New Pods should appear and transition to the Running state.

Scaling the ReplicaSet

Scaling Up

To increase the ReplicaSet to five replicas, run:
Then verify the updated Pod count:
Expected output:

Scaling Down

To scale the ReplicaSet down, you can edit the resource directly:
  1. Open the ReplicaSet for editing:
  2. Modify the replicas value from 5 to 2 in the YAML:
  3. Save your changes. Verify the update with:
The ReplicaSet will now adjust to maintain only two Pods.

Final Commands Recap

Below is a summary of the commands used throughout this lab exercise:
Happy learning and successful Kubernetes management!

Watch Video