148422597X Kubernetes Management Design Patterns [Vohra 2017-01-29] {E559F6BB}

marco.cirilli
from marco.cirilli More from this publisher
19.06.2021 Views

Chapter 4 ■ Using Multiple ZonesCopy the following source code into claim.json:{"kind": "PersistentVolumeClaim","apiVersion": "v1","metadata": {"name": "claim1","annotations": {"volume.alpha.kubernetes.io/storage-class": "foo"}},"spec": {"accessModes": ["ReadWriteOnce"],"resources": {"requests": {"storage": "3Gi"}}}}The resulting claim1.json is shown in the vi editor in Figure 4-34.Figure 4-34. A PersistentVolumeClaim claim1.json113

Chapter 4 ■ Using Multiple ZonesCreate a PVC with the kubectl create command:kubectl create -f claim1.jsonList the persistent volumes, including labels:kubectl get pv --show-labelsThe persistent volume is listed as being consumed by the persistent volume claim:kubectl get pvcAs the command’s output indicates, a persistentvolumeclaim is created. The persistent volume islisted to be in the us-east-1b zone as shown in Figure 4-35.Figure 4-35. A PersistentVolumeClaim claim1.json114Next, define a pod specification that makes use of the PVC.sudo vi pod.yamlCopy the following code to pod.yaml:---apiVersion: v1kind: Podmetadata:name: nginxspec:containers:-image: nginxname: nginxvolumeMounts:-mountPath: /var/www/htmlname: pvvolumes:-

Chapter 4 ■ Using Multiple Zones

Copy the following source code into claim.json:

{

"kind": "PersistentVolumeClaim",

"apiVersion": "v1",

"metadata": {

"name": "claim1",

"annotations": {

"volume.alpha.kubernetes.io/storage-class": "foo"

}

},

"spec": {

"accessModes": [

"ReadWriteOnce"

],

"resources": {

"requests": {

"storage": "3Gi"

}

}

}

}

The resulting claim1.json is shown in the vi editor in Figure 4-34.

Figure 4-34. A PersistentVolumeClaim claim1.json

113

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!