From b7f68b16b56f4ad6945f9a54205b13d3490bcd1d Mon Sep 17 00:00:00 2001 From: Karthik Date: Thu, 7 Jan 2021 21:40:02 -0500 Subject: [PATCH] Add documentation and examples for dynamic provisioning --- docs/README.md | 26 +++++++++- docs/iam-policy-example.json | 38 ++++++++++++++ .../kubernetes/dynamic_provisioning/README.md | 49 +++++++++++++++++++ .../dynamic_provisioning/specs/pod.yaml | 30 ++++++++++++ .../specs/storageclass.yaml | 12 +++++ 5 files changed, 153 insertions(+), 2 deletions(-) create mode 100644 docs/iam-policy-example.json create mode 100644 examples/kubernetes/dynamic_provisioning/README.md create mode 100644 examples/kubernetes/dynamic_provisioning/specs/pod.yaml create mode 100644 examples/kubernetes/dynamic_provisioning/specs/storageclass.yaml diff --git a/docs/README.md b/docs/README.md index 2f8fb8724..675b541e0 100644 --- a/docs/README.md +++ b/docs/README.md @@ -19,9 +19,24 @@ The [Amazon Elastic File System](https://aws.amazon.com/efs/) Container Storage Currently only static provisioning is supported. This means an AWS EFS file system needs to be created manually on AWS first. After that it can be mounted inside a container as a volume using the driver. The following CSI interfaces are implemented: -* Node Service: NodePublishVolume, NodeUnpublishVolume, NodeGetCapabilities, NodeGetInfo, NodeGetId +* Controller Service: CreateVolume, DeleteVolume, ControllerGetCapabilities, ValidateVolumeCapabilities +* Node Service: NodePublishVolume, NodeUnpublishVolume, NodeGetCapabilities, NodeGetInfo, NodeGetId, NodeGetVolumeStats * Identity Service: GetPluginInfo, GetPluginCapabilities, Probe +### CreateVolume Parameters +| Parameters | Values | Default | Optional | Description | +|---------------------|--------|---------|-----------|-------------| +| provisioningMode | efs-ap | | false | Type of volume provisioned by efs. Currently, Access Points are supported. | +| fileSystemId | | | false | File System under which access points are created. | +| directoryPerms | | | false | Directory permissions for [Access Point root directory](https://docs.aws.amazon.com/efs/latest/ug/efs-access-points.html#enforce-root-directory-access-point) creation. | +| gidRangeStart | | 50000 | true | Start range of the POSIX group Id to be applied for [Access Point root directory](https://docs.aws.amazon.com/efs/latest/ug/efs-access-points.html#enforce-root-directory-access-point) creation. | +| gidRangeEnd | | 7000000 | true | End range of the POSIX group Id. | +| basePath | | | true | Path under which access points for dynamic provisioning is created. If this parameter is not specified, access points are created under the root directory of the file system | + +**Notes**: +* Custom Posix group Id range for Access Point root directory must include both `gidRangeStart` and `gidRangeEnd` parameters. +* When using a custom Posix group ID range, there is a possibility for the driver to run out of available POSIX group Ids. We suggest ensuring custom group ID range is large enough or create a new storage class with a new file system to provision additional volumes. + ### Encryption In Transit One of the advantages of using EFS is that it provides [encryption in transit](https://aws.amazon.com/blogs/aws/new-encryption-of-data-in-transit-for-amazon-efs/) support using TLS. Using encryption in transit, data will be encrypted during its transition over the network to the EFS service. This provides an extra layer of defence-in-depth for applications that requires strict security compliance. @@ -53,6 +68,7 @@ The following sections are Kubernetes specific. If you are a Kubernetes user, us ### Features * Static provisioning - EFS file system needs to be created manually first, then it could be mounted inside container as a persistent volume (PV) using the driver. +* Dynamic provisioning - Uses a persistent volume claim (PVC) to dynamically provision a persistent volume (PV). On Creating a PVC, kuberenetes requests EFS to create an Access Point in a file system which will be used to mount the PV. * Mount Options - Mount options can be specified in the persistent volume (PV) to define how the volume should be mounted. * Encryption of data in transit - EFS file systems are mounted with encryption in transit enabled by default in the master branch version of the driver. @@ -60,7 +76,12 @@ The following sections are Kubernetes specific. If you are a Kubernetes user, us * Since EFS is an elastic file system it doesn't really enforce any file system capacity. The actual storage capacity value in persistent volume and persistent volume claim is not used when creating the file system. However, since the storage capacity is a required field by Kubernetes, you must specify the value and you can use any valid value for the capacity. ### Installation -Deploy the driver: +####Set up driver permission: +The driver requires IAM permission to talk to Amazon EFS to manage the volume on user's behalf. There are several methods to grant driver IAM permission: +* Using IAM Role for Service Account (Recommended if you're using EKS): create an [IAM Role for service accounts](https://docs.aws.amazon.com/eks/latest/userguide/iam-roles-for-service-accounts.html) with the [required permissions](./iam-policy-example.json). Uncomment annotations and put the IAM role ARN in [service-account manifest](../deploy/kubernetes/base/serviceaccount-csi-controller.yaml) +* Using IAM [instance profile](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_switch-role-ec2_instance-profiles.html) - grant all the worker nodes with [required permissions](./iam-policy-example.json) by attaching policy to the instance profile of the worker. + +####Deploy the driver: If you want to deploy the stable driver: ```sh @@ -87,6 +108,7 @@ Before the example, you need to: #### Example links * [Static provisioning](../examples/kubernetes/static_provisioning/README.md) +* [Dynamic provisioning](../examples/kubernetes/dynamic_provisioning/README.md) * [Encryption in transit](../examples/kubernetes/encryption_in_transit/README.md) * [Accessing the file system from multiple pods](../examples/kubernetes/multiple_pods/README.md) * [Consume EFS in StatefulSets](../examples/kubernetes/statefulset/README.md) diff --git a/docs/iam-policy-example.json b/docs/iam-policy-example.json new file mode 100644 index 000000000..1ee311869 --- /dev/null +++ b/docs/iam-policy-example.json @@ -0,0 +1,38 @@ +{ + "Version": "2012-10-17", + "Statement": [ + { + "Sid": "VisualEditor0", + "Effect": "Allow", + "Action": [ + "elasticfilesystem:DescribeAccessPoints", + "elasticfilesystem:DescribeFileSystems" + ], + "Resource": "*" + }, + { + "Sid": "VisualEditor1", + "Effect": "Allow", + "Action": [ + "elasticfilesystem:CreateAccessPoint" + ], + "Resource": "*", + "Condition": { + "StringLike": { + "aws:RequestTag/efs.csi.aws.com/cluster": "true" + } + } + }, + { + "Sid": "VisualEditor2", + "Effect": "Allow", + "Action": "elasticfilesystem:DeleteAccessPoint", + "Resource": "*", + "Condition": { + "StringEquals": { + "aws:ResourceTag/efs.csi.aws.com/cluster": "true" + } + } + } + ] +} \ No newline at end of file diff --git a/examples/kubernetes/dynamic_provisioning/README.md b/examples/kubernetes/dynamic_provisioning/README.md new file mode 100644 index 000000000..45e839063 --- /dev/null +++ b/examples/kubernetes/dynamic_provisioning/README.md @@ -0,0 +1,49 @@ +## Dynamic Provisioning +This example shows how to create a dynamically provisioned volume created through [EFS access points](https://docs.aws.amazon.com/efs/latest/ug/efs-access-points.html) and Persistent Volume Claim (PVC) and consume it from a pod. + +**Note**: this example requires Kubernetes v1.13+ and driver version >= 1.1.0. + +### Edit [StorageClass](./specs/storageclass.yaml) + +``` +kind: StorageClass +apiVersion: storage.k8s.io/v1 +metadata: + name: efs-sc +provisioner: efs.csi.aws.com +mountOptions: + - tls +parameters: + provisioningMode: efs-ap + fileSystemId: fs-92107410 + directoryPerms: "700" + gidRangeStart: "1000" + gidRangeEnd: "2000" + basePath: "/dynamic_provisioning" +``` +* provisioningMode - The type of volume to be provisioned by efs. Currently, only access point based provisioning is supported `efs-ap`. +* fileSystemId - The file system under which Access Point is created. +* directoryPerms - Directory Permissions of the root directory created by Access Point. +* gidRangeStart (Optional) - Starting range of Posix Group ID to be applied onto the root directory of the access point. Default value is 50000. +* gidRangeEnd (Optional) - Ending range of Posix Group ID. Default value is 7000000. +* basePath (Optional) - Path on the file system under which access point root directory is created. If path is not provided, access points root directory are created under the root of the file system. + +### Deploy the Example +Create storage class, persistent volume claim (PVC) and the pod which consumes PV: +```sh +>> kubectl apply -f examples/kubernetes/dynamic_provisioning/specs/storageclass.yaml +>> kubectl apply -f examples/kubernetes/dynamic_provisioning/specs/pod.yaml +``` + +### Check EFS filesystem is used +After the objects are created, verify that pod is running: + +```sh +>> kubectl get pods +``` + +Also you can verify that data is written onto EFS filesystem: + +```sh +>> kubectl exec -ti efs-app -- tail -f /data/out.txt +``` diff --git a/examples/kubernetes/dynamic_provisioning/specs/pod.yaml b/examples/kubernetes/dynamic_provisioning/specs/pod.yaml new file mode 100644 index 000000000..522a690e1 --- /dev/null +++ b/examples/kubernetes/dynamic_provisioning/specs/pod.yaml @@ -0,0 +1,30 @@ +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: efs-claim +spec: + accessModes: + - ReadWriteMany + storageClassName: efs-sc + resources: + requests: + storage: 5Gi +--- +apiVersion: v1 +kind: Pod +metadata: + name: efs-app +spec: + containers: + - name: app + image: centos + command: ["/bin/sh"] + args: ["-c", "while true; do echo $(date -u) >> /data/out; sleep 5; done"] + volumeMounts: + - name: persistent-storage + mountPath: /data + volumes: + - name: persistent-storage + persistentVolumeClaim: + claimName: efs-claim \ No newline at end of file diff --git a/examples/kubernetes/dynamic_provisioning/specs/storageclass.yaml b/examples/kubernetes/dynamic_provisioning/specs/storageclass.yaml new file mode 100644 index 000000000..1821bfe69 --- /dev/null +++ b/examples/kubernetes/dynamic_provisioning/specs/storageclass.yaml @@ -0,0 +1,12 @@ +kind: StorageClass +apiVersion: storage.k8s.io/v1 +metadata: + name: efs-sc +provisioner: efs.csi.aws.com +parameters: + provisioningMode: efs-ap + fileSystemId: fs-92107410 + directoryPerms: "700" + gidRangeStart: "1000" + gidRangeEnd: "2000" + basePath: "/dynamic_provisioning" \ No newline at end of file