|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * storage/persistent_storage-aws.adoc |
| 4 | + |
| 5 | +:_content-type: PROCEDURE |
| 6 | +[id="aws-container-persistent-volumes-encrypt_{context}"] |
| 7 | += Encrypting container persistent volumes on AWS with a KMS key |
| 8 | + |
| 9 | +Defining a KMS key to encrypt container-persistent volumes on AWS is useful when you have explicit compliance and security guidelines when deploying to AWS. |
| 10 | + |
| 11 | +.Prerequisites |
| 12 | + |
| 13 | +* Underlying infrastructure must contain storage. |
| 14 | +* You must create a customer KMS key on AWS. |
| 15 | +
|
| 16 | +.Procedure |
| 17 | + |
| 18 | +. Create a storage class: |
| 19 | ++ |
| 20 | +[source,yaml] |
| 21 | +---- |
| 22 | +$ cat << EOF | oc create -f - |
| 23 | +apiVersion: storage.k8s.io/v1 |
| 24 | +kind: StorageClass |
| 25 | +metadata: |
| 26 | + name: <storage-class-name> <1> |
| 27 | +parameters: |
| 28 | + fsType: ext4 <2> |
| 29 | + encrypted: "true" |
| 30 | + kmsKeyId: keyvalue <3> |
| 31 | +provisioner: ebs.csi.aws.com |
| 32 | +reclaimPolicy: Delete |
| 33 | +volumeBindingMode: WaitForFirstConsumer |
| 34 | +EOF |
| 35 | +---- |
| 36 | +<1> Specifies the name of the storage class. |
| 37 | +<2> File system that is created on provisioned volumes. |
| 38 | +<3> Specifies the full Amazon Resource Name (ARN) of the key to use when encrypting the container-persistent volume. If you do not provide any key, but the `encrypted` field is set to `true`, then the default KMS key is used. See link:https://docs.aws.amazon.com/kms/latest/developerguide/find-cmk-id-arn.html[Finding the key ID and key ARN on AWS] in the AWS documentation. |
| 39 | + |
| 40 | +. Create a persistent volume claim (PVC) with the storage class specifying the KMS key: |
| 41 | ++ |
| 42 | +[source,yaml] |
| 43 | +---- |
| 44 | +$ cat << EOF | oc create -f - |
| 45 | +apiVersion: v1 |
| 46 | +kind: PersistentVolumeClaim |
| 47 | +metadata: |
| 48 | + name: mypvc |
| 49 | +spec: |
| 50 | + accessModes: |
| 51 | + - ReadWriteOnce |
| 52 | + volumeMode: Filesystem |
| 53 | + storageClassName: <storage-class-name> |
| 54 | + resources: |
| 55 | + requests: |
| 56 | + storage: 1Gi |
| 57 | +EOF |
| 58 | +---- |
| 59 | + |
| 60 | +. Create workload containers to consume the PVC: |
| 61 | ++ |
| 62 | +[source,yaml] |
| 63 | +---- |
| 64 | +$ cat << EOF | oc create -f - |
| 65 | +kind: Pod |
| 66 | +metadata: |
| 67 | + name: mypod |
| 68 | +spec: |
| 69 | + containers: |
| 70 | + - name: httpd |
| 71 | + image: quay.io/centos7/httpd-24-centos7 |
| 72 | + ports: |
| 73 | + - containerPort: 80 |
| 74 | + volumeMounts: |
| 75 | + - mountPath: /mnt/storage |
| 76 | + name: data |
| 77 | + volumes: |
| 78 | + - name: data |
| 79 | + persistentVolumeClaim: |
| 80 | + claimName: mypvc |
| 81 | +EOF |
| 82 | +---- |
0 commit comments