0
0
Kubernetesdevops~20 mins

StatefulSets for stateful applications in Kubernetes - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
StatefulSets Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Why use StatefulSets instead of Deployments for databases?

Which of the following reasons best explains why StatefulSets are preferred over Deployments for running databases in Kubernetes?

AStatefulSets allow pods to share the same storage volume, making data sharing easier for databases.
BStatefulSets automatically scale pods horizontally without any configuration, unlike Deployments.
CStatefulSets restart pods faster than Deployments, improving database availability.
DStatefulSets provide stable network IDs and persistent storage for each pod, which databases need to maintain data consistency.
Attempts:
2 left
💡 Hint

Think about what databases need to keep their data safe and consistent even if pods restart.

💻 Command Output
intermediate
1:30remaining
Output of StatefulSet pod names

Given a StatefulSet named web with 3 replicas, what will be the output of the command kubectl get pods -l app=web -o custom-columns=NAME:.metadata.name --no-headers?

Kubernetes
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: web
spec:
  serviceName: "web"
  replicas: 3
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
      - name: nginx
        image: nginx
A
web-1
web-2
web-3
B
web
web
web
C
web-0
web-1
web-2
D
web-0
web-1
Attempts:
2 left
💡 Hint

StatefulSet pods have stable, ordinal names starting at 0.

Configuration
advanced
2:00remaining
Correct volumeClaimTemplates for StatefulSet

Which of the following volumeClaimTemplates configurations correctly creates persistent volumes for each pod in a StatefulSet?

Kubernetes
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: db
spec:
  replicas: 2
  selector:
    matchLabels:
      app: db
  serviceName: "db"
  template:
    metadata:
      labels:
        app: db
    spec:
      containers:
      - name: mysql
        image: mysql
        volumeMounts:
        - name: data
          mountPath: /var/lib/mysql
  volumeClaimTemplates:
A
- metadata:
    name: data
  spec:
    accessModes: ["ReadWriteOnce"]
    resources:
      requests:
        storage: 1Gi
B
- metadata:
    name: data
  spec:
    accessModes: ["ReadWriteMany"]
    resources:
      requests:
        storage: 1Gi
C
- metadata:
    name: data
  spec:
    accessModes: ["ReadOnlyMany"]
    resources:
      requests:
        storage: 1Gi
D
- metadata:
    name: data
  spec:
    accessModes: ["ReadWriteOnce"]
    resources:
      limits:
        storage: 1Gi
Attempts:
2 left
💡 Hint

Think about the access mode that allows a single pod to write to its volume.

Troubleshoot
advanced
2:00remaining
Why does a StatefulSet pod fail to attach volume?

A StatefulSet pod fails to start with an error about volume attachment. The volumeClaimTemplates are correct. What is the most likely cause?

AThe PersistentVolumeClaim is bound to a PersistentVolume in a different availability zone than the pod.
BThe pod's container image is missing the volume mount path.
CThe StatefulSet replicas count is set to zero.
DThe pod label selector does not match the StatefulSet selector.
Attempts:
2 left
💡 Hint

Consider cloud storage constraints related to zones or regions.

🔀 Workflow
expert
2:30remaining
Order of pod termination in StatefulSet rolling update

During a rolling update of a StatefulSet with 3 replicas, in which order are the pods terminated and updated?

A3,1,2
B3,2,1
C2,3,1
D1,2,3
Attempts:
2 left
💡 Hint

Think about the ordinal index order StatefulSets use for updates.