如何将加密的 Amazon EFS 文件系统挂载到 Amazon EKS 中的容器组(pod)上?

2 分钟阅读
0

我想将加密的 Amazon Elastic File System (Amazon EFS) 文件系统挂载到 Amazon Elastic Kubernetes Service (Amazon EKS) 中的一个容器组(pod)上。

简短描述

可以使用 TLS 加密传输中的数据,也可以加密静态数据

**注意:**如果在运行 AWS 命令行界面(AWS CLI)命令时收到错误,请参阅排查 AWS CLI 错误。此外,请确保您使用的是最新的 AWS CLI 版本

解决方法

使用 TLS 加密传输中的数据

要使用 TLS 加密传输中的数据,请完成以下步骤:

  1. 为 Amazon EKS 集群部署 Amazon EFS 容器存储接口 (CSI) 驱动程序

  2. 为集群创建一个不加密的 Amazon EFS 文件系统
    **注意:**创建文件系统时,请在 EKS 节点所在的所有可用区中为 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。 验证数据是否写入 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
  1. 验证数据是否写入 Amazon EFS 文件系统:
kubectl exec -ti app1 -- tail /data/out1.txt
kubectl exec -ti app2 -- tail /data/out1.txt
AWS 官方
AWS 官方已更新 1 年前