0
0
Kubernetesdevops~20 mins

ReplicaSet definition in Kubernetes - Practice Problems & Coding Challenges

Choose your learning style9 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.