This quiz is part of the DevOpsTheHardWay course.

Please answer the quiz and click the "Test" button at the bottom right.

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

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:

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?

Question 4

What is the different between a PV and a PVC?

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.

Question 6

When a PV is configured with the retain reclaim policy, what happens if the associated PVC is deleted?

Question 7

Can 2 PVCs be bound to the same PV?

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:

license