Creating persistent volumes 

The following steps are a prerequisite to creating the persistent volume manually since we are not using an enterprise storage provisioner such as IBM Spectrum Scale, NetApp, Dell EMC, RedHat Ceph, or Portworx, which will create the persistent volume automatically when a persistent volume claim is made. To create a persistent volume, follow these steps:

  1. Create a Consul persistent volumes directory:
$ sudo mkdir -p /var/lib/consul{0,1,2}
  1. Create a consul namespace:
$ kubectl create ns consul
namespace/consul created
  1. Grant cluster_admin to the consul namespace:
$ kubectl create clusterrolebinding consul-role-binding --clusterrole=cluster-admin --group=system:serviceaccounts:consul
clusterrolebinding.rbac.authorization.k8s.io/consul-role-binding created

The following are the definitions of the no-provisioner storage class and the persistent volumes that are provided by the 01-create-pv-consul.yaml script:

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: consul-storage
provisioner: kubernetes.io/no-provisioner
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer
  1. Define the first physical volume:
apiVersion: v1
kind: PersistentVolume
metadata:
name: consul-data-0
spec:
accessModes:
- ReadWriteOnce
capacity:
storage: 2Gi
claimRef:
apiVersion: v1
kind: PersistentVolumeClaim
name: data-consul-consul-consul-server-0
namespace: consul
local:
path: /var/lib/consul0

The following portion of the 01-create-pv-consul.yaml script specifies the node that the persistent volume will be created on:

nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- osc01.servicemesh.local
persistentVolumeReclaimPolicy: Retain
storageClassName: consul-storage
---

This is an example of a persistent volume claim. We'll do the same for the second and third ones in the same script, that is, 01-create-pv-consul.yaml.

  1. Create a storage class and three persistent volumes:
$ kubectl -n consul apply -f 01-create-pv-consul.yaml
storageclass.storage.k8s.io/consul-storage created
persistentvolume/consul-data-0 created
persistentvolume/consul-data-1 created
persistentvolume/consul-data-2 created

Now that we've created the persistent volumes, we can go ahead and download the Consul Helm chart for installing Consul. We'll learn how to do this in the next section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.140.242.165