Exercise
Exercise: Storage¶
-
Setting up the default StorageClass
SKS defines a StorageClass to provision storage dynamically, it is named exoscale-sbs. This StorageClass is not set as the default one, run the following command to do so:
kubectl patch storageclass exoscale-sbs -p '{"metadata": {"annotations": {"storageclass.kubernetes.io/is-default-class": "true"}}}'
-
In a file named pvc-redis.yaml, define the specification for a PersistentVolumeClaim with the following characteristics:
- name: redis
- ReadWriteOnce mode
- request for 1OG storage
Warning
10Gi if the minimum capacity we can require on Exoscale
Then modify the redis Deployment specification by adding a volume based on this PersistentVolumeClaim, and use the volumeMounts instruction to ensure that the associated PersistentVolume is mounted in the /data directory of the redis container.
-
In a file named pvc-db.yaml containing the specification for a PersistentVolumeClaim with the following characteristics:
- name: db
- ReadWriteOnce mode
- request for 10G of storage
Then modify the db Deployment specification by adding a volume based on this PersistentVolumeClaim, and use the volumeMounts instruction to ensure that the associated PersistentVolume is mounted in the /var/lib/postgresql/data directory of the postgres container.
-
Deploy the application defined in these specifications and verify that it is working correctly.
-
List the PersistentVolumeClaim resources. What do you observe?
-
Delete the application.
Tip
-
already done
-
The specification to define the PersistentVolumeClaim named redis:
pvc-redis.yamlapiVersion: v1 kind: PersistentVolumeClaim metadata: name: redis spec: accessModes: - ReadWriteOnce resources: requests: storage: 10Gi
The redis Deployment is modified as follows:
deploy-redis.yamlapiVersion: apps/v1 kind: Deployment metadata: labels: app: redis name: redis spec: replicas: 1 selector: matchLabels: app: redis template: metadata: labels: app: redis spec: containers: - image: redis:7.0.8-alpine3.17 name: redis volumeMounts: - name: data mountPath: /data volumes: - name: data persistentVolumeClaim: claimName: redis
-
The specification to define the PersistentVolumeClaim named db:
pvc-db.yamlapiVersion: v1 kind: PersistentVolumeClaim metadata: name: db spec: accessModes: - ReadWriteOnce resources: requests: storage: 10Gi
The db Deployment is modified as follows:
deploy-db.yamlapiVersion: apps/v1 kind: Deployment metadata: labels: app: db name: db spec: replicas: 1 selector: matchLabels: app: db template: metadata: labels: app: db spec: containers: - image: postgres:15.1-alpine3.17 name: postgres env: - name: POSTGRES_PASSWORD valueFrom: secretKeyRef: name: db key: password volumeMounts: - name: data mountPath: /var/lib/postgresql/data ports: - containerPort: 5432 name: postgres volumes: - name: data persistentVolumeClaim: claimName: db
-
Deploy the application using the following command from the manifests directory:
kubectl apply -f .
Using the IP address of one of the cluster nodes, you can access the vote and result interfaces via ports 31000 and 31001 respectively.
-
You can list the PersistentVolumeClaim resources and observe that a PersistentVolume has been created for each of the 2 PVCs.
List of PersistentVolumeClaims:
$ kubectl get pvc NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE persistentvolumeclaim/redis Bound pvc-789e3c5c-4402-4b96-b09d-ee441e8ade1d 10Gi RWO local-path 39s persistentvolumeclaim/db Bound pvc-75b9a32c-eab5-4452-a9b8-12d41dd74e7a 10Gi RWO local-path 39s
List of PersistentVolumes:
$ kubectl get pv NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE persistentvolume/pvc-789e3c5c-4402-4b96-b09d-ee441e8ade1d 10Gi RWO Delete Bound default/redis local-path 32s persistentvolume/pvc-75b9a32c-eab5-4452-a9b8-12d41dd74e7a 10Gi RWO Delete Bound default/db local-path 32s
The volumes can be listed from the Exoscale console
-
Delete the application using the following command from the manifests directory:
kubectl delete -f .