Using GCE PD volumes for persistent storage

As an alternative to creating PVCs and dynamically creating volumes, you can also create a volume manually and attach it to your application directly as a persistent volume by observing the following steps:

  1. Create a GCE PD volume in the same zone as your worker nodes:
$ gcloud beta compute disks create gce-disk-1 --region us-central1 --replica-zones us-central1-b,us-central1-c 
Created [https://www.googleapis.com/compute/beta/projects/devopscookbook/regions/us-central1/disks/gce-disk-1].
NAME ZONE SIZE_GB TYPE STATUS
gce-disk-1 500 pd-standard READY
  1. Create a PV using the existing volume name, gce-disk-1:
$ cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: PersistentVolume
metadata:
name: gce-disk-1
spec:
storageClassName: ""
capacity:
storage: 500G
accessModes:
- ReadWriteOnce
gcePersistentDisk:
pdName: gce-disk-1
fsType: ext4
EOF
  1. Create a PVC using the PV name, gce-disk-1:
$ cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-gcedisk1
spec:
storageClassName: ""
volumeName: gce-disk-1
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 500G
EOF
  1. Deploy a test application using the volumeMounts name, gce-disk-1, that you have created in Step 1:
$ cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
name: test-server
spec:
containers:
- image: gcr.io/google_containers/test-webserver
name: test-container
volumeMounts:
- mountPath: /test-ebs
name: test-volume
volumes:
- name: test-volume
persistentVolumeClaim:
claimName: pvc-gcedisk1
EOF
  1. Verify that your pod is in the Running state:
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
test-server 1/1 Running 0 4m32s

The main advantage of manually created PVs is that PVs are not attached to a single cluster or namespace. They exist as a resource on your GCP account and they can even be shared across clusters. On the other hand, dynamically created PVCs only exist in the namespace created and can only be used by a pod within that same namespace.

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

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