Which of the following reasons best explains why StatefulSets are preferred over Deployments for running databases in Kubernetes?
Think about what databases need to keep their data safe and consistent even if pods restart.
StatefulSets assign stable network IDs and persistent storage to each pod, which is essential for databases to maintain consistent data. Deployments do not guarantee stable identities or storage.
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?
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
StatefulSet pods have stable, ordinal names starting at 0.
StatefulSet pods are named with the StatefulSet name plus an ordinal index starting at 0, so the pods are web-0, web-1, and web-2.
Which of the following volumeClaimTemplates configurations correctly creates persistent volumes for each pod in a StatefulSet?
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:
Think about the access mode that allows a single pod to write to its volume.
StatefulSet pods require ReadWriteOnce access mode for persistent volumes so each pod can write to its own volume exclusively. ReadWriteMany or ReadOnlyMany are not suitable here.
A StatefulSet pod fails to start with an error about volume attachment. The volumeClaimTemplates are correct. What is the most likely cause?
Consider cloud storage constraints related to zones or regions.
In cloud environments, PersistentVolumes are often tied to specific zones. If a pod schedules in a different zone than the volume, it cannot attach the volume, causing startup failure.
During a rolling update of a StatefulSet with 3 replicas, in which order are the pods terminated and updated?
Think about the ordinal index order StatefulSets use for updates.
StatefulSets update pods in reverse ordinal order, starting from the highest index pod (web-2) down to the lowest (web-0), to maintain stable identity and availability.