I want to mount an encrypted Amazon Elastic File System (Amazon EFS) file system to a pod in Amazon Elastic Kubernetes Service (Amazon EKS).
Resolution
You can encrypt your data in your Amazon EFS file system while it's in data in transit and data at rest states. Data in transit is set by default.
Note: If you receive errors when you run AWS Command Line Interface (AWS CLI) commands, then see Troubleshoot AWS CLI errors. Also, make sure that you're using the most recent AWS CLI version.
Encrypt data in transit with TLS
To encrypt your data in transit with TLS, complete the following steps:
-
Deploy the Amazon EFS Container Storage Interface (CSI) driver for your Amazon EKS cluster.
-
Create an Amazon EFS file system.
Note: When you create the file system, create a mount target for Amazon EFS in all Availability Zones where your EKS nodes are located.
-
Clone the GitHub repository to your local system.
git clone https://github.com/kubernetes-sigs/aws-efs-csi-driver.git
-
Navigate to the encryption_in_transit example directory:
cd aws-efs-csi-driver/examples/kubernetes/encryption_in_transit/
-
To retrieve your Amazon EFS file system ID, run the following describe-file-systems command:
aws efs describe-file-systems --query "FileSystems[*].FileSystemId" --output text
-
Open the pv.yaml file in the /examples/kubernetes/encryption_in_transit/specs/ directory. Then, replace the value of VolumeHandle with the FileSystemId of the Amazon EFS file system that you're mounting.
The pv.yaml file should look similar to the following:
apiVersion: v1
kind: PersistentVolume
metadata:
name: efs-pv
spec:
capacity:
storage: 5Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: efs-sc
csi:
driver: efs.csi.aws.com
volumeHandle: FileSystemId
volumeAttributes:
encryptInTransit: "true"
Note: Replace FileSystemId with your Amazon EFS file system ID. The volumeAttributes: encryptInTransit mount option turns on encryption in transit.
-
Deploy the storage class, persistent volume claim, persistent volume, and pod from the /examples/kubernetes/encryption_in_transit/specs/ directory:
kubectl apply -f specs/storageclass.yaml
kubectl apply -f specs/pv.yaml
kubectl apply -f specs/claim.yaml
kubectl apply -f specs/pod.yaml
-
To verify that your pod is in a running state, run the following command:
kubectl get pods
-
To list the persistent volumes in the default namespace, run the following command:
kubectl get pv
-
To describe the persistent volume, run the following command:
kubectl describe pv efs-pv
Note: The Amazon EFS file system ID is listed as the VolumeHandle.
-
To verify that the data is written onto the Amazon EFS file system, run the following command:
kubectl exec -ti efs-app -- tail -f /data/out.txt
Encrypt data at rest
Note: After you create an EFS file system, you can't change its encryption setting. This means that you can't modify an unencrypted file system to make it encrypted.
To encrypt data at rest, complete the following steps:
-
Deploy the Amazon EFS CSI driver for your Amazon EKS cluster.
-
Create an Amazon EFS file system with encryption at rest active.
Note: The AWS management console automatically turns on encryption at rest with an AWS managed AWS Key Management Service (AWS KMS) key. The AWS CLI and SDK require you to turn on encryption explicitly.
-
Clone the following GitHub repository to your local system:
git clone https://github.com/kubernetes-sigs/aws-efs-csi-driver.git
-
Navigate to the multiple_pods example directory:
cd aws-efs-csi-driver/examples/kubernetes/multiple_pods/
-
To retrieve your Amazon EFS file system ID, run the following command:
aws efs describe-file-systems
Example output:
{
"FileSystems": [
{
"SizeInBytes": {
"Timestamp": **timestamp**,
"Value": **value**
},
"ThroughputMode": "**throughput-mode**",
"CreationToken": "**creation-token**",
"Encrypted": true,
"CreationTime": **creation-time**,
"PerformanceMode": "**performance-mode**",
"FileSystemId": "**file-system-id**",
"NumberOfMountTargets": **number**,
"LifeCycleState": "available",
"KmsKeyId": "arn:aws:kms:ap-southeast-1:**account-id**:key/**key-id**",
"OwnerId": "**owner-id**"
}
]
}
-
Open the pv.yaml file in the /examples/kubernetes/multiple_pods/specs/ directory. Then, replace the value of volumeHandle with the FileSystemId of the Amazon EFS file system that you're mounting.
The pv.yaml file should look similar to the following:
apiVersion: v1
kind: PersistentVolume
metadata:
name: efs-pv
spec:
capacity:
storage: 5Gi
volumeMode: Filesystem
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
storageClassName: efs-sc
csi:
driver: efs.csi.aws.com
volumeHandle: FileSystemId
Note: Replace FileSystemId with your Amazon EFS file system ID.
-
Deploy the storage class, persistent volume claim, persistent volume, and pod from the /examples/kubernetes/multiple_pods/specs/ directory:
kubectl apply -f specs/storageclass.yaml
kubectl apply -f specs/pv.yaml
kubectl apply -f specs/claim.yaml
kubectl apply -f specs/pod1.yaml
kubectl apply -f specs/pod2.yaml
-
To verify that your pod is in a running state, run the following command:
kubectl get pods
-
To list the persistent volumes in the default namespace, run the following command:
kubectl get pv
-
To describe the persistent volume, run the following command:
kubectl describe pv efs-pv
-
To verify that the data is written onto the Amazon EFS file system, run the following commands:
kubectl exec -ti app1 -- tail /data/out1.txt
kubectl exec -ti app2 -- tail /data/out1.txt