Installing the EBS CSI driver to manage EBS volumes

The Amazon EBS CSI driver provides a Kubernetes CSI interface that allows Amazon EKS clusters to simply manage the life cycle of Amazon EBS volumes for persistent volumes. In this recipe, we will learn how to install the EBS CSI driver by observing the following steps:

  1. EBS CSI communicates with your AWS volume to create volumes on demand. Therefore, it requires access credentials. Replace the key_id and access_key values here with your AWS credentials and configure CSI driver permission using a secret resource:
$ cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Secret
metadata:
name: aws-secret
namespace: kube-system
stringData:
key_id: "YOUR_KEY_ID_HERE"
access_key: "YOUR_ACCESS_KEY_HERE"
EOF
  1. Deploy the AWS EBS CSI driver from its repository location. The following command will create ClusterRoleBindings, CSI controller deployment, and an ebs-csi-node DaemonSet that will run every worker node you have:
$ kubectl apply -k "github.com/kubernetes-sigs/aws-ebs-csi-driver/deploy/kubernetes/overlays/stable/?ref=master"
  1. Verify that the driver is running:
$ kubectl get pods -n kube-system | grep ebs-csi
ebs-csi-controller-8579f977f4-ljfhm 4/4 Running 0 2m37s
ebs-csi-controller-8579f977f4-qw6ld 4/4 Running 0 2m37s
ebs-csi-node-5x8nh 3/3 Running 0 2m37s
ebs-csi-node-cfghj 3/3 Running 0 2m37s
ebs-csi-node-xp569 3/3 Running 0 2m37s
ebs-csi-node-z45hn 3/3 Running 0 2m37s
  1. Now, create a new storage class that will use ebs.csi.aws.com as the provisioner:
$ cat <<EOF | kubectl apply -f -
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: aws-csi-ebs
provisioner: ebs.csi.aws.com
volumeBindingMode: WaitForFirstConsumer
EOF
  1. Create a PVC:
$ cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: csi-ebs-pvc
spec:
accessModes:
- ReadWriteOnce
storageClassName: aws-csi-ebs
resources:
requests:
storage: 4Gi
EOF
  1. Create a pod that will use the PVC and that writes to the /data/out.txt file:
$ cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
name: app
spec:
containers:
- name: app
image: centos
command: ["/bin/sh"]
args: ["-c", "while true; do echo $(date -u) >> /data/out.txt; sleep 5; done"]
volumeMounts:
- name: persistent-storage
mountPath: /data
volumes:
- name: persistent-storage
persistentVolumeClaim:
claimName: csi-ebs-pvc
EOF
  1. Verify that our mytestapp pod writes data to the volume:
$ kubectl exec -it mytestapp cat /data/out.txt
Mon Sep 9 17:40:25 UTC 2019
  1. Remove resources by deleting the pod and the PVC by using the following command:
$ kubectl delete pod mytestapp && kubectl delete pvc csi-ebs-pvc

Now you know how to use CSI drivers to provision EBS volumes. A CSI driver provides a unified interface to answer storage requests on Kubernetes. As long as the driver is installed and has the functionality implemented by the driver, it can be consumed by the user regardless of the underlying storage system.

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

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