You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
3.0 KiB

  1. # AWS EBS CSI Driver
  2. AWS EBS CSI driver allows you to provision EBS volumes for pods in EC2 instances. The old in-tree AWS cloud provider is deprecated and will be removed in future versions of Kubernetes. So transitioning to the CSI driver is advised.
  3. To enable AWS EBS CSI driver, uncomment the `aws_ebs_csi_enabled` option in `group_vars/all/aws.yml` and set it to `true`.
  4. To set the number of replicas for the AWS CSI controller, you can change `aws_ebs_csi_controller_replicas` option in `group_vars/all/aws.yml`.
  5. Make sure to add a role, for your EC2 instances hosting Kubernetes, that allows it to do the actions necessary to request a volume and attach it: [AWS CSI Policy](https://github.com/kubernetes-sigs/aws-ebs-csi-driver/blob/master/docs/example-iam-policy.json)
  6. If you want to deploy the AWS EBS storage class used with the CSI Driver, you should set `persistent_volumes_enabled` in `group_vars/k8s_cluster/k8s_cluster.yml` to `true`.
  7. You can now run the kubespray playbook (cluster.yml) to deploy Kubernetes over AWS EC2 with EBS CSI Driver enabled.
  8. ## Usage example
  9. To check if AWS EBS CSI Driver is deployed properly, check that the ebs-csi pods are running:
  10. ```ShellSession
  11. $ kubectl -n kube-system get pods | grep ebs
  12. ebs-csi-controller-85d86bccc5-8gtq5 4/4 Running 4 40s
  13. ebs-csi-node-n4b99 3/3 Running 3 40s
  14. ```
  15. Check the associated storage class (if you enabled persistent_volumes):
  16. ```ShellSession
  17. $ kubectl get storageclass
  18. NAME PROVISIONER AGE
  19. ebs-sc ebs.csi.aws.com 45s
  20. ```
  21. You can run a PVC and an example Pod using this file `ebs-pod.yml`:
  22. ```yml
  23. --
  24. apiVersion: v1
  25. kind: PersistentVolumeClaim
  26. metadata:
  27. name: ebs-claim
  28. spec:
  29. accessModes:
  30. - ReadWriteOnce
  31. storageClassName: ebs-sc
  32. resources:
  33. requests:
  34. storage: 1Gi
  35. ---
  36. apiVersion: v1
  37. kind: Pod
  38. metadata:
  39. name: app
  40. spec:
  41. containers:
  42. - name: app
  43. image: centos
  44. command: ["/bin/sh"]
  45. args: ["-c", "while true; do echo $(date -u) >> /data/out.txt; sleep 5; done"]
  46. volumeMounts:
  47. - name: persistent-storage
  48. mountPath: /data
  49. volumes:
  50. - name: persistent-storage
  51. persistentVolumeClaim:
  52. claimName: ebs-claim
  53. ```
  54. Apply this conf to your cluster: ```kubectl apply -f ebs-pod.yml```
  55. You should see the PVC provisioned and bound:
  56. ```ShellSession
  57. $ kubectl get pvc
  58. NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
  59. ebs-claim Bound pvc-0034cb9e-1ddd-4b3f-bb9e-0b5edbf5194c 1Gi RWO ebs-sc 50s
  60. ```
  61. And the volume mounted to the example Pod (wait until the Pod is Running):
  62. ```ShellSession
  63. $ kubectl exec -it app -- df -h | grep data
  64. /dev/nvme1n1 1014M 34M 981M 4% /data
  65. ```
  66. ## More info
  67. For further information about the AWS EBS CSI Driver, you can refer to this page: [AWS EBS Driver](https://github.com/kubernetes-sigs/aws-ebs-csi-driver/).