Elastic Block Store as StorageClass

We've learned about Volumes in Chapter 2, Walking through Kubernetes Concepts. We know PersistentVolumeClaims is used to abstract storage resources from users. It can dynamically provision the PersistentVolume via StorageClass. The default provisioner in StorageClass in AWS CloudProvider is Elastic Block Storage Service‎ (aws-ebs). Whenever you request a PVC, aws-ebs provisioner will create a volume in AWS EBS.

Let's check the storage class in our cluster:

// list all storageclass
# kubectl get storageclass
NAME PROVISIONER AGE
default kubernetes.io/aws-ebs 2h
gp2 (default) kubernetes.io/aws-ebs 2h
In this recipe, we'll reuse the PVC example we mentioned in Chapter 2-6:
# cat chapter2/2-6_volumes/2-6-7_pvc.yaml
apiVersion: "v1"
kind: "PersistentVolumeClaim"
metadata:
name: "pvclaim01"
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
// create pvc
# kubectl create -f chapter2/2-6_volumes/2-6-7_pvc.yaml
persistentvolumeclaim "pvclaim01" created
// check pvc is created successfully.
# kubectl get pvc
NAME STATUS VOLUME CAPACITY
pvclaim01 Bound pvc-e3d881d4-402e-11e8-b124-0ef0c7f25d36 1Gi
ACCESS MODES STORAGECLASS AGE
RWO gp2 16m

After PVC is created, an associated PV will be created:

# kubectl get pv
NAME CAPACITY ACCESS MODES
pvc-e3d881d4-402e-11e8-b124-0ef0c7f25d36 1Gi RWO
RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
Delete Bound default/pvclaim01 gp2 16m

You can take a closer look at PV here:

# kubectl describe pv pvc-e3d881d4-402e-11e8-b124-0ef0c7f25d36
Name: pvc-e3d881d4-402e-11e8-b124-0ef0c7f25d36
Labels: failure-domain.beta.kubernetes.io/region=us-east-1
failure-domain.beta.kubernetes.io/zone=us-east-1a
Annotations: kubernetes.io/createdby=aws-ebs-dynamic-provisioner
pv.kubernetes.io/bound-by-controller=yes
pv.kubernetes.io/provisioned-by=kubernetes.io/aws-ebs
Claim: default/pvclaim01
...
Source:
Type: AWSElasticBlockStore (a Persistent Disk resource in AWS)
VolumeID: aws://us-east-1a/vol-035ca31b9cc1820d7
FSType: ext4
Partition: 0
ReadOnly: false

We can find that it's associated with the claim we just created pvclaim01 and the source type is AWSElasticBlockStore, as expected.

We can use AWS CLI to inspect the volume we created in EBS. Using the --filter Name=tag-value we can filter the volumes in EBS:

// aws ec2 describe-volumes --filter Name=tag-value,Values=$PV_NAME
# aws ec2 describe-volumes --filter Name=tag-value,Values="pvc-e3d881d4-402e-11e8-b124-0ef0c7f25d36"{
"Volumes": [
{
"AvailabilityZone": "us-east-1a",
"Tags": [
{ "Value": "k8s-cookbook.net",
"Key": "KubernetesCluster" },
{ "Value": "default",
"Key": "kubernetes.io/created-for/pvc/namespace" },
{ "Value": "k8s-cookbook.net-dynamic-pvc-e3d881d4-402e-11e8-b124-0ef0c7f25d36",
"Key": "Name" },
{ "Value": "pvclaim01",
"Key": "kubernetes.io/created-for/pvc/name" },
{ "Value": "owned",
"Key": "kubernetes.io/cluster/k8s-cookbook.net" },
{ "Value": "pvc-e3d881d4-402e-11e8-b124-0ef0c7f25d36",
"Key": "kubernetes.io/created-for/pv/name" }],
"VolumeType": "gp2",
"VolumeId": "vol-035ca31b9cc1820d7",
...
}
]
}

We can see that the EBS resource has been tagged with lots of different values: by observing these tags, we can know which Kubernetes cluster, namespace, PVC, and PV are associated with this EBS volume.

Thanks to dynamic provisioning that StorageClass and CloudProvider support, Volume management is no longer a huge pain. We can create and destroy PV on the fly.

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

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