Bird
Raised Fist0
Kubernetesdevops~20 mins

ReplicaSet definition in Kubernetes - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
ReplicaSet Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
What is the primary purpose of a ReplicaSet in Kubernetes?

Choose the best description of what a ReplicaSet does in a Kubernetes cluster.

AIt ensures a specified number of pod replicas are running at any time.
BIt manages network policies between pods.
CIt stores persistent data for pods.
DIt schedules pods to specific nodes based on resource availability.
Attempts:
2 left
💡 Hint

Think about what keeps pods running in the right quantity.

❓ Configuration
intermediate
2:00remaining
Identify the correct ReplicaSet YAML snippet for 3 replicas of a pod named 'nginx'.

Which YAML snippet correctly defines a ReplicaSet with 3 replicas running the 'nginx' container?

A
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: nginx-rs
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
B
apiVersion: v1
kind: ReplicaSet
metadata:
  name: nginx-rs
spec:
  replicas: 3
  selector:
    app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
C
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: nginx-rs
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80
D
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: nginx-rs
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
Attempts:
2 left
💡 Hint

Check apiVersion, replicas count, and selector format carefully.

💻 Command Output
advanced
1:30remaining
What is the output of 'kubectl get rs' after applying this ReplicaSet YAML?

Given this ReplicaSet YAML applied to the cluster, what will be the output of kubectl get rs?

Kubernetes
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: test-rs
spec:
  replicas: 4
  selector:
    matchLabels:
      app: test
  template:
    metadata:
      labels:
        app: test
    spec:
      containers:
      - name: test-container
        image: busybox
        command: ['sleep', '3600']
A
NAME      DESIRED   CURRENT   READY   AGE
test-rs   1         1         1       <age>
B
NAME      DESIRED   CURRENT   READY   AGE
test-rs   4         0         0       <age>
C
NAME      DESIRED   CURRENT   READY   AGE
test-rs   4         4         4       <age>
DError from server (NotFound): replicasets.apps "test-rs" not found
Attempts:
2 left
💡 Hint

Think about what happens when you apply a ReplicaSet with 4 replicas.

❓ Troubleshoot
advanced
2:00remaining
Why does this ReplicaSet fail to create pods?

Given this ReplicaSet YAML, pods are not being created. What is the most likely cause?

Kubernetes
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: fail-rs
spec:
  replicas: 2
  selector:
    matchLabels:
      app: fail
  template:
    metadata:
      labels:
        app: fail-app
    spec:
      containers:
      - name: fail-container
        image: nginx
AThe apiVersion 'apps/v1' is incorrect for ReplicaSet.
BThe selector labels do not match the pod template labels.
CThe container image 'nginx' is invalid and causes pod creation failure.
DThe replicas count must be at least 3 for pods to be created.
Attempts:
2 left
💡 Hint

Check if the selector and pod labels match exactly.

✅ Best Practice
expert
2:30remaining
Which practice ensures safe updates to ReplicaSets in production?

When updating a ReplicaSet in a production environment, which practice is best to avoid downtime?

AScale the ReplicaSet to zero, update the pods manually, then scale back.
BDelete the existing ReplicaSet and create a new one with updated specs.
CDirectly edit the ReplicaSet to change the container image version.
DUse a Deployment to manage ReplicaSets and perform rolling updates.
Attempts:
2 left
💡 Hint

Think about how Kubernetes manages updates without downtime.

Practice

(1/5)
1. What is the main purpose of a ReplicaSet in Kubernetes?
easy
A. To manage network policies between pods
B. To store persistent data for pods
C. To ensure a specified number of pod replicas are running at all times
D. To schedule pods on specific nodes

Solution

  1. Step 1: Understand ReplicaSet role

    A ReplicaSet's job is to keep a stable set of pod replicas running.
  2. Step 2: Compare options with ReplicaSet function

    Only To ensure a specified number of pod replicas are running at all times describes maintaining pod replicas, which is the ReplicaSet's purpose.
  3. Final Answer:

    To ensure a specified number of pod replicas are running at all times -> Option C
  4. Quick Check:

    ReplicaSet manages pod count = A [OK]
Hint: ReplicaSet = keeps pods running in set number [OK]
Common Mistakes:
  • Confusing ReplicaSet with PersistentVolume
  • Thinking ReplicaSet manages network policies
  • Mixing ReplicaSet with pod scheduling
2. Which of the following is the correct minimal YAML snippet to define a ReplicaSet with 3 replicas?
easy
A. apiVersion: apps/v1\nkind: ReplicaSet\nmetadata:\n name: my-rs\nspec:\n replicas: 3\n selector:\n matchLabels:\n app: myapp\n template:\n metadata:\n labels:\n app: myapp\n spec:\n containers:\n - name: nginx\n image: nginx
B. apiVersion: v1\nkind: ReplicaSet\nmetadata:\n name: my-rs\nspec:\n replicas: 3\n selector:\n app: myapp\n template:\n metadata:\n labels:\n app: myapp\n spec:\n containers:\n - name: nginx\n image: nginx
C. apiVersion: apps/v1\nkind: ReplicaSet\nmetadata:\n name: my-rs\nspec:\n replicas: three\n selector:\n matchLabels:\n app: myapp\n template:\n metadata:\n labels:\n app: myapp\n spec:\n containers:\n - name: nginx\n image: nginx
D. apiVersion: apps/v1\nkind: ReplicaSet\nmetadata:\n name: my-rs\nspec:\n replicas: 3\n selector:\n matchLabels:\n app: myapp\n template:\n metadata:\n labels:\n app: otherapp\n spec:\n containers:\n - name: nginx\n image: nginx

Solution

  1. Step 1: Check apiVersion and kind

    ReplicaSet requires apiVersion: apps/v1 and kind: ReplicaSet. The option with apiVersion: v1 is invalid.
  2. Step 2: Validate replicas and selector-template match

    Replicas must be an integer like 3, not string 'three'. Selector labels must match template labels exactly (one option has template app: otherapp mismatch). Only one option has all correct: apps/v1, replicas: 3, matching labels with proper structure.
  3. Final Answer:

    Correct YAML with apiVersion apps/v1, replicas: 3, matching selector and template labels -> Option A
  4. Quick Check:

    YAML syntax + matching labels = D [OK]
Hint: Match selector labels exactly with template labels [OK]
Common Mistakes:
  • Using wrong apiVersion
  • Setting replicas as string instead of number
  • Mismatching selector and template labels
3. Given this ReplicaSet YAML snippet, what will be the number of pods running after applying it?
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: test-rs
spec:
  replicas: 2
  selector:
    matchLabels:
      app: test
  template:
    metadata:
      labels:
        app: test
    spec:
      containers:
      - name: busybox
        image: busybox
        command: ['sleep', '3600']
medium
A. 3 pods
B. 1 pod
C. 0 pods
D. 2 pods

Solution

  1. Step 1: Check replicas field

    The spec.replicas is set to 2, so Kubernetes will try to run 2 pods matching the selector.
  2. Step 2: Confirm selector and template labels match

    Selector matches label app: test, and template labels also have app: test, so pods will be created.
  3. Final Answer:

    2 pods -> Option D
  4. Quick Check:

    replicas = 2 pods running [OK]
Hint: replicas number = pods running if labels match [OK]
Common Mistakes:
  • Ignoring label selector and template label matching
  • Assuming pods run without matching labels
  • Confusing replicas with container count
4. You applied a ReplicaSet YAML but no pods are created. Which of these is the most likely cause?
medium
A. The replicas field is set to 0
B. The selector labels do not match the pod template labels
C. The container image name is misspelled
D. The ReplicaSet name is missing

Solution

  1. Step 1: Understand pod creation depends on selector matching template labels

    If selector labels don't match pod template labels, ReplicaSet won't manage any pods.
  2. Step 2: Evaluate other options

    Replicas 0 means no pods, but question says pods expected. Misspelled image causes pod crash, not zero pods. Name missing causes YAML error, not silent no pods.
  3. Final Answer:

    The selector labels do not match the pod template labels -> Option B
  4. Quick Check:

    Selector-template label mismatch = no pods [OK]
Hint: Selector and template labels must match exactly [OK]
Common Mistakes:
  • Assuming image typo prevents pod creation
  • Ignoring selector-template label mismatch
  • Thinking ReplicaSet name is optional
5. You want to update a ReplicaSet to increase replicas from 2 to 5 but keep the same pods running without downtime. What is the best approach?
hard
A. Scale the ReplicaSet using kubectl scale command to 5 replicas
B. Delete the ReplicaSet and create a new one with replicas: 5
C. Edit the ReplicaSet YAML to set replicas: 5 and apply it
D. Change the pod template labels to new values and apply

Solution

  1. Step 1: Understand scaling ReplicaSet

    Scaling with kubectl scale updates replicas live without downtime.
  2. Step 2: Evaluate other options

    Editing YAML and applying works but less safe than scale command. Deleting ReplicaSet causes downtime. Changing labels breaks pod matching.
  3. Final Answer:

    Scale the ReplicaSet using kubectl scale command to 5 replicas -> Option A
  4. Quick Check:

    Use kubectl scale for live replica changes [OK]
Hint: Use kubectl scale to change replicas live [OK]
Common Mistakes:
  • Deleting ReplicaSet causes downtime
  • Changing labels breaks pod matching
  • Editing YAML directly risks errors
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard