Static provisioning – Managing Advanced Kubernetes Resources-1

Static provisioning is the traditional method of provisioning volumes. It requires someone (typically an administrator) to manually provision a disk and create a PersistentVolume resource using the disk information. The developer can then use the PersistentVolume resource within their StatefulSet resource, as in the following diagram:

Figure 6.9 – Static provisioning

Let’s now look at a static provisioning example.

To access the resources for this section, cd into the following:

$ cd ~/modern-devops/ch6/statefulsets/

So, we first need to create a disk within the cloud platform. Since we’re using Google Cloud, let’s proceed and use the gcloud commands to do so.

Use the following command to create a persistent zonal disk. Ensure that you use the same zone as your Kubernetes cluster. As we are using the us-central1-a zone for the Kubernetes cluster, we will use the same in the following command:

$ gcloud compute disks create nginx-manual \

–size 50GB –type pd-ssd –zone us-central1-a

Created [https://www.googleapis.com/compute/v1/projects/<project_id>/zones/us-central1-a/ disks/nginx-manual].

NAME                 ZONE                   SIZE_GB  TYPE       STATUS

nginx-manual  us-central1-a  50            pd-ssd  READY

As the disk is now ready, we can then create a PersistentVolume resource from it.

The manifest file, nginx-manual-pv.yaml, looks like this:

apiVersion: v1

kind: PersistentVolume

metadata:

name: nginx-manual-pv

labels:

usage: nginx-manual-disk

spec:

capacity:

storage: 50G

accessModes:

  • ReadWriteOnce gcePersistentDisk:

pdName: nginx-manual

fsType: ext4

The spec section contains capacity, accessModes, and the kind of disk it needs to provision.

You can specify one or more access modes to a PersistentVolumes:

  • ReadWriteOnce: Only one pod can read and write to the disk at a time; therefore, you cannot mount such a volume to multiple pods
  • ReadOnlyMany: Multiple pods can read from the same volume simultaneously, but no pod can write to the disk
  • ReadWriteMany: Multiple pods can read and write to the same volume at once

Tip

Not all kinds of storage support all access modes. You need to decide the volume type during the initial requirement analysis and architectural assessment phase.

OK—let’s now go and apply the manifest to provision the PersistentVolume resource using the following command:

$ kubectl apply -f nginx-manual-pv.yaml

Let’s now check whether the Persistent Volume is available by using the following command:

$ kubectl get pv

NAME

CAPACITY

ACCESS MODES

RECLAIM POLICY

STATUS

nginx-manual-pv

50G

RWO

Retain

Available

As the Persistent Volume is now available, we must create a headless Service resource to help maintain network identity in the StatefulSet resource. The following nginx-manual-service. yaml manifest describes it:

apiVersion: v1

kind: Service

metadata:

name: nginx-manual

labels:

app: nginx-manual

spec:

ports:

– port: 80

name: web

clusterIP: None

selector:

app: nginx-manual

It is very similar to the regular Service resource, except that we have specified clusterIP as None.

Now, let’s go and apply the manifest using the following command:

$ kubectl apply -f nginx-manual-service.yaml

Related Posts

Static provisioning – Managing Advanced Kubernetes Resources-2

As the Service resource is created, we can create a StatefulSet resource that uses the created PersistentVolume and Service resources. The StatefulSet resource manifest, nginx-manual-statefulset.yaml, looks like…

StatefulSet resources – Managing Advanced Kubernetes Resources

StatefulSet resources help manage stateful applications. They are similar to Deployment resources, but unlike a Deployment resource, they also keep track of state and require Volume and…

Managing stateful applications – Managing Advanced Kubernetes Resources

Imagine you’re a librarian in a magical library. You have a bunch of enchanted books that store valuable knowledge. Each book has a unique story and is…

Horizontal Pod autoscaling – Managing Advanced Kubernetes Resources-2

Now, let’s autoscale this deployment. The Deployment resource needs at least 1 pod replica and can have a maximum of 5 pod replicas while maintaining an average…

Horizontal Pod autoscaling – Managing Advanced Kubernetes Resources-1

Imagine you’re the manager of a snack bar at a park. On a sunny day, lots of people come to enjoy the park, and they all want…

Name-based routing – Managing Advanced Kubernetes Resources

Name-based or FQDN-based routing relies on the host header we pass while making an HTTP request. The Ingress resource can route based on the header. For example,…

Leave a Reply

Your email address will not be published. Required fields are marked *