> ## Content Index
> Fetch the complete content index at: https://skills.devopscube.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to Troubleshoot and Fix a Kubernetes ReplicaSet
- URL: https://skills.devopscube.com/troubleshoot-a-kubernetes-replicaset/
- Published: 2026-09-17T14:51:58.000Z
- Updated: 2026-10-14T11:59:01.000Z
- Author: Sulaiman
- Tags: Troubleshooting, #CKA-Exam-question, #docs, #blog

A ReplicaSet manifest is provided at `rs.yaml`. The manifest contains configuration errors.

`rs.yaml` manifest:

```YAML
apiVersion: v1
kind: Replicaset
metadata:
  name: webapp
spec:
  replicas: 3
  selector:
    matchLabels:
      tier: app
  template:
    metadata:
      labels:
        tier: web
    spec:
      containers:
      - name: nginx-container
        image: nginx
```

Your task is to review the provided YAML file, identify and fix the errors, and deploy the ReplicaSet in the `default` namespace.

The ReplicaSet must:

- Be named `webapp`
- Maintain 3 replicas.
- Use the `nginx` container image.
- Correctly match the ReplicaSet selector with the Pod labels.
- Have all 3 managed Pods in the Running state.

Ensure that all pods managed by the ReplicaSet are in the Running state.

📚

For more details about `ReplicaSet`, refer to the [official Kubernetes documentation](https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/?ref=skills.devopscube.com).

🙅‍♀️

Do not create a new manifest from scratch.

---

## Identify the Errors

There are   **issues** in the provided manifest.

### Compare the two manifests

Broken Fixed 

rs.yaml before 

apiVersion: v1 kind: Replicaset metadata:  name: webapp spec:  replicas: 3  selector:  matchLabels:  tier: app  template:  metadata:  labels:  tier: web  spec:  containers:  \- name: nginx-container  image: nginx 

rs.yaml after Copy 

apiVersion: apps/v1 kind: ReplicaSet metadata:  name: webapp spec:  replicas: 3  selector:  matchLabels:  tier: web  template:  metadata:  labels:  tier: web  spec:  containers:  \- name: nginx-container  image: nginx 

These are the problems you'll identify once you open the file.

**Line 1: the wrong API group**

`apiVersion: v1` is for core resources like Pods, Services, ConfigMaps, and Secrets. ReplicaSet belongs to the `apps` group, so use `apiVersion: apps/v1`. In the exam, use `kubectl api-resources` to check the correct API group.

**Line 2: The kind is case `sensitive`**

`Replicaset` is incorrect. Kubernetes uses `ReplicaSet` with both words capitalized. Always match the exact capitalization shown by `kubectl api-resources`.

**Line 9:** the selector does not match the pod labels

The selector looks for `tier: app`, but the pod template uses `tier: web`, so the ReplicaSet cannot match its own pods.

Both values must be identical. Here, change the selector to `tier: web`.

The API server rejects it with: `selector does not match template labels`.

## Verify your work

All four have to pass for the task to count.

Apply the correct YAML file:

```sh
$ kubectl apply -f rs.yaml

replicaset.apps/webapp created
```

Check current and ready for all 3 pods:

```sh
$ kubectl get rs webapp

NAME     DESIRED   CURRENT   READY   AGE
webapp   3         3         3       40s
```

Check that the three pods are running, not pending or ImagePullBackOff:

```sh
$ kubectl get pods -l tier=web
NAME           READY   STATUS    RESTARTS   AGE
webapp-9l7wq   1/1     Running   0          81s
webapp-m6bhf   1/1     Running   0          81s
webapp-pvp7h   1/1     Running   0          81s
```

1. The ReplicaSet owns those pods:

```sh
$ kubectl describe rs webapp | grep -A3 Replicas 

Replicas:     3 current / 3 desired
Pods Status:  3 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
  Labels:  tier=web
```

---

## Why Does the Selector Need to Match?

A ReplicaSet uses its **selector** to identify and manage Pods with matching labels. The labels defined in the Pod template must match the ReplicaSet's selector. 

For example, `matchLabels: tier: web` must match the Pod label `tier: web`. If the labels do not match, the ReplicaSet cannot correctly identify or manage the Pods.

---

## CKA Exam Tips

These tips will help you quickly identify key Kubernetes concepts and avoid common mistakes during the CKA exam and CKA hands-on practice.

## Tip 1: Know the API Group

`ReplicaSet` uses apps/v1\. Common resources in this group include Deployment, ReplicaSet, StatefulSet, and DaemonSet.

## Tip 2: Kubernetes Resource Kinds Are Case-Sensitive

Use `ReplicaSet` and `Deployment`, not `Replicaset` or `deployment`.

## Tip 3: Always Check Selectors

For a ReplicaSet, make sure `selector.matchLabels` matches the `Pod template's metadata.labels`.

## Tip 4: Check the Replica Count

If the task requires three Pods, set `replicas: 3` and verify with `kubectl get rs`. Look for DESIRED, CURRENT, and READY all showing 3.