如何将加密的 Amazon EFS 文件系统挂载到 Amazon EKS 的 Pod 中?
上次更新日期:2021 年 4 月 21 日
我想要将加密的 Amazon Elastic File System (Amazon EFS) 文件系统挂载到 Amazon Elastic Kubernetes Service (Amazon EKS) 中的 Pod。
简短描述
您可以使用以下方法之一对 Amazon EFS 文件系统中的数据进行加密:
在“解决方案”部分,根据您的需求选择加密方法。
注意:如果您在运行 AWS 命令行界面 (AWS CLI) 命令时遇到错误,请确保您使用的是最新版的 AWS CLI。
解决方法
使用 TLS 加密传输中的数据
1. 为 Amazon EKS 集群部署 Amazon EFS Container Storage Interface (CSI) 驱动程序。
2. 为集群创建一个不加密的 Amazon EFS 文件系统。
3. 将 GitHub 存储库克隆到本地系统:
git clone https://github.com/kubernetes-sigs/aws-efs-csi-driver.git
4. 转至 encryption_in_transit 示例目录:
cd aws-efs-csi-driver/examples/kubernetes/encryption_in_transit/
5. 检索 Amazon EFS 文件系统 ID:
aws efs describe-file-systems --query "FileSystems[*].FileSystemId" --output text
6. 转至 /examples/kubernetes/encryption_in_transit/specs/ 目录中的 pv.yaml 文件。然后,将 VolumeHandle 的值替换为需要挂载的 Amazon EFS 文件系统的 FileSystemId。例如:
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"
注意:volumeAttributes: encryptInTransit 挂载选项将会激活传输中的加密。
7. 从 /examples/kubernetes/encryption_in_transit/specs/ 目录部署存储类、持久性卷声明、持久性卷和 Pod:
kubectl apply -f specs/storageclass.yaml
kubectl apply -f specs/pv.yaml
kubectl apply -f specs/claim.yaml
kubectl apply -f specs/pod.yaml
8. 创建对象后,验证您的 Pod 是否正在运行:
kubectl get pods
9. 在默认命名空间中列出持久性卷:
kubectl get pv
10. 描述持久性卷:
kubectl describe pv efs-pv
注意:Amazon EFS 文件系统 ID 将作为 VolumeHandle 列出。
11. 验证数据是否已写入到 Amazon EFS 文件系统:
kubectl exec -ti efs-app -- tail -f /data/out.txt
加密静态数据
1. 为 Amazon EKS 集群部署 Amazon EFS CSI 驱动程序。
2. 通过启用静态加密为 Amazon EKS 集群创建 Amazon EFS 文件系统。
3. 将以下 GitHub 存储库克隆到本地系统:
git clone https://github.com/kubernetes-sigs/aws-efs-csi-driver.git
4. 转至 multiple_pods 示例目录:
cd aws-efs-csi-driver/examples/kubernetes/multiple_pods/
5. 检索 Amazon EFS 文件系统 ID:
aws efs describe-file-systems
示例输出:
{
"FileSystems": [
{
"SizeInBytes": {
"Timestamp": ,
"Value":
},
"ThroughputMode": "",
"CreationToken": “”,
"Encrypted": true,
"CreationTime": ,
"PerformanceMode": "",
"FileSystemId": "[FileSystemId]",
"NumberOfMountTargets": ,
"LifeCycleState": "available",
"KmsKeyId": "arn:aws:kms:ap-southeast-1:<account_id>:key/854df848-fdd1-46e3-ab97-b4875c4190e6",
"OwnerId": ""
},
]
}
6. 转至 /examples/kubernetes/multiple_pods/specs/ 目录中的 pv.yaml 文件。然后,将 volumeHandle 的值替换为需要挂载的 Amazon EFS 文件系统的 FileSystemId。例如:
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]
7. 从 /examples/kubernetes/multiple_pods/specs/ 目录部署存储类、持久性卷声明、持久性卷和 Pod:
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
8. 创建对象后,验证您的 Pod 是否正在运行:
kubectl get pods
9. 在默认命名空间中列出持久性卷:
kubectl get pv
10. 描述持久性卷:
kubectl describe pv efs-pv
11. 验证数据是否已写入到 Amazon EFS 文件系统:
kubectl exec -ti app1 -- tail /data/out1.txt
kubectl exec -ti app2 -- tail /data/out1.txt