Please answer the quiz and click the "Test" button at the bottom right.This quiz is part of the DevOpsTheHardWay course.
Kubernetes - StatefulSet and Storages - multichoice questions
Given a cluster with a running MySQL StatefulSet:
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mysql
spec:
serviceName: "mysql"
replicas: 3
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql-container
image: mysql:latest
env:
- name: MYSQL_ROOT_PASSWORD
value: "your-root-password"
- name: MYSQL_DATABASE
value: "your-database-name"
- name: MYSQL_USER
value: "your-mysql-user"
- name: MYSQL_PASSWORD
value: "your-mysql-password"
ports:
- containerPort: 3306
volumeMounts:
- name: mysql-persistent-storage
mountPath: /var/lib/mysql
volumeClaimTemplates:
- metadata:
name: mysql-persistent-storage
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 5Gi
Answer the below 3 questions.
Question 1
Choose all correct statement(s)
Performing the below command:
kubectl scale statefulset mysql --replicas=2
- Will not delete the volume associated with
mysql-2
replica. - Will delete the volume associated with
mysql-2
replica. - Will delete the PVC associated with
mysql-0
replica. - Will not delete the PVC associated with
mysql-2
replica.
Question 2
You are told that when the StatefulSet has been deployed for the first time, for some reason, readiness probes of pod mysql-1
were failed.
Choose the correct statement(s) regarding the Pod status and Pod condition of mysql-0
and mysql-2
:
- Pod
mysql-2
status is Pending. - Pod
mysql-2
status is Unknown and the Initialized condition is met. - Pod
mysql-0
status is Running and the Ready condition is met. - Pod
mysql-0
status is Terminating and the Ready condition is met.
Question 3
During RollingUpdate
, the StatefulSet controller will delete and recreate each Pod in the StatefulSet,
in reverse ordinal order.
Here is the Pod status before the rolling update:
$ kubectl get pod -l app=mysql
NAME READY STATUS RESTARTS AGE
mysql-0 1/1 Running 0 7m
mysql-1 1/1 Running 0 7m
mysql-2 1/1 Running 0 8m
And during the rolling update (using the -w
flag to "watch" the output updates in real-time):
$ kubectl get pod -l app=mysql -w
NAME READY STATUS RESTARTS AGE
mysql-2 1/1 Terminating 0 8m
mysql-2 1/1 Terminating 0 8m
mysql-2 0/1 Terminating 0 8m
mysql-2 0/1 Terminating 0 8m
mysql-2 0/1 Terminating 0 8m
mysql-2 0/1 Terminating 0 8m
mysql-1 1/1 Terminating 0 0s
mysql-1 0/1 Terminating 0 0s
mysql-1 0/1 Terminating 0 0s
mysql-1 0/1 Terminating 0 19s
mysql-2 0/1 Pending 0 8m
mysql-2 0/1 Pending 0 8m
mysql-2 0/1 ContainerCreating 0 8m
mysql-2 1/1 Running 0 8m
mysql-1 0/1 Pending 0 0s
mysql-1 0/1 Pending 0 0s
mysql-1 0/1 ContainerCreating 0 0s
mysql-1 1/1 Running 0 6s
mysql-0 1/1 Terminating 0 7m
mysql-0 1/1 Terminating 0 7m
mysql-0 0/1 Terminating 0 7m
mysql-0 0/1 Terminating 0 7m
mysql-0 0/1 Terminating 0 7m
mysql-0 0/1 Terminating 0 7m
mysql-0 0/1 Pending 0 0s
mysql-0 0/1 Pending 0 0s
mysql-0 0/1 ContainerCreating 0 0s
mysql-0 1/1 Running 0 10s
What's wrong with the above output?
- The output is ok.
- The pods should be terminated in a reverse order:
mysql-0
first, thenmysql-1
, andmysql-3
last. -
mysql-1
is terminating beforemysql-2
is Running. - None of the above.
Question 4
What is the different between a PV and a PVC?
- PV is used by Pods, while PVC is used by PersistentVolumeClaims.
- PV is dynamically created by Kubernetes, while PVC is statically provisioned by cluster administrators.
- PV represents physical storage resources, while PVC is a request for storage resources.
- PV is namespace-specific, while PVC is cluster-wide.
Question 5
A StatefulSet uses hostPath
for storage. After performing a rolling update, some Pod was scheduled on a different node than it was scheduled originally.
- The data on the
hostPath
is automatically replicated to the new node. - The Pod fails to start on the new node, and the data remains on the original node.
- The data on the
hostPath
is lost sincehostPath
is specific to the node's local filesystem. - In a StatefulSet, Pods are always scheduled on the same node they were scheduled originally.
Question 6
When a PV is configured with the retain
reclaim policy, what happens if the associated PVC is deleted?
- Both PV and PVC are deleted, freeing up the storage resources.
- PV is retained, and the associated PVC is deleted, leaving the PV intact.
- Both PV and PVC are retained, preserving the storage resources.
- PV is deleted, and the associated PVC is retained, allowing the PV to be used by another PVC.
Question 7
Can 2 PVCs be bound to the same PV?
- No!
- Yes!
- Only in the PV accessModes is ReadWriteMany.
- Only in the PV accessModes is ReadWriteMany and is located in the same namespace of the PVC.
Question 8
Given a PVC:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
Which is bound to the following PV:
apiVersion: v1
kind: PersistentVolume
metadata:
name: my-pv
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
Now consider two Pods:
apiVersion: v1
kind: Pod
metadata:
name: pod-1
spec:
containers:
- name: container-1
image: nginx:latest
volumeMounts:
- name: my-storage
mountPath: /data
volumes:
- name: my-storage
persistentVolumeClaim:
claimName: my-pvc
---
apiVersion: v1
kind: Pod
metadata:
name: pod-2
spec:
containers:
- name: container-2
image: busybox:latest
command: ["/bin/sh", "-c", "sleep 3600"]
volumeMounts:
- name: my-storage
mountPath: /data
volumes:
- name: my-storage
persistentVolumeClaim:
claimName: my-pvc
Choose the correct sentence:
- The above example can not work since the two Pods can not use the same PVC.
- The above example works.
- The above example can work only if the two Pods are scheduled on the same node.
- None of the above.