Exercise

1 minute read

In this exercise, you’ll persist the VotingApp’s databases.

By default, k3s comes with the default StorageClass named local-path which can be verified using the following command.

$ kubectl get storageclass
NAME                   PROVISIONER             RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
local-path (default)   rancher.io/local-path   Delete          WaitForFirstConsumer   false                  1h4m
  1. In a file named pvc-redis.yaml, define the specification for a PersistentVolumeClaim with the following characteristics:
  • name: redis
  • ReadWriteOnce mode
  • request for 1G storage

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.

  1. In a file named pvc-db.yaml containing the specification for a PersistentVolumeClaim with the following characteristics:

    • name: db
    • ReadWriteOnce mode
    • request for 1G 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.

  2. Deploy the application defined in these specifications and verify that it is working correctly.

  3. List the PersistentVolumeClaim resources. What do you observe?

  4. Delete the application.