K8s PVC & Secret

Mansi Dadheech
4 min readJun 23, 2020

--

Previously we learned about storage in aws and kubernetes.
In continuation to that we are going to learn more about storage in kubernetes.

Persistent Volume Claim:

If any pods goes down replica set can relaunch it but files what we created are completely destroyed as pods provide temporary storage.
To make them permanent, while launching pod we can mount any folder to centralized storage.

For mounting some directory with storage, we want permanent storage per directory or folder. We can’t use object or block storage. We can only use file storage.
PVC is a request for storage by pods.Claims can request specific size and access modes (e.g., they can be mounted once read/write).

As there are multiple storage like cloud EFS,Cluster storage,Ceph,Glusterfs etc. To operate all these storage we need a program or interface which can access all of them that program is known as storage class.

There are to different kinds of PVC:

  • Static PVC: Let say we need a pod of 20Gi storage than first we have to create separate block for 20Gi PVC and then request for storage.
  • Dynamic PVC: When pod request any storage suppose 10Gi then dynamically create PVC of 10Gi.

Creating PVC:

To create PVC, we create PVC.yml file:

After running this file we get a pvc and also pv dynamically with the same access mode and size.

Now we can mount pvc with any folder inside container.

By describing pod we can confirm that pvc get attached to container.

Similarly , we create a pvc for MYSQL database so that whenever a client comes to wordpress, data stores permanently using PVC.

Creating PVC for mysql:

After creating PVC we mount /var/www/html folder with pod.

Now, we login in that container , start mysql then create some table.

When we delete that pod, the table we created in poddb database remain inside that volume and we can use it by attaching it to other container.

As we can see , we deleted our previous pod and launched a new pod.Through this pod we can access our database.

Secret:

A k8s concepts which helps us to store and manage sensitive information like password, keys etc.

We can create secrets using CLI,YAML file and terraform.

By CLI:

We can change output format by “-o”.

By YAML:

Here we have to give password and username in Base64 encoded form.We can encode or decode online .

In the same way we can add username database password in MYSQL environment variable.

Thanks for reading and thanks to vimal sir!!

--

--

Mansi Dadheech

Exploring various disciplines to broaden my own pursuits✨.