必要前提
创建AWS IAM policy绑定到集群serviceaccount以授予EFS CSI调用AWS API的权限
curl -o iam-policy-example.json https://raw.githubusercontent.com/kubernetes-sigs/aws-efs-csi-driver/master/docs/iam-policy-example.json
2.创建IAM policy
aws iam create-policy \
--policy-name AmazonEKS_EFS_CSI_Driver_Policy \
--policy-document file://iam-policy-example.json
3.创建IAM Role并附件上述IAM policy,将其绑定到集群serviceaccount
对应集群名字及aws区域id请根据实际环境配置
eksctl create iamserviceaccount \
--cluster my-cluster \
--namespace kube-system \
--name efs-csi-controller-sa \
--attach-policy-arn arn:aws:iam::111122223333:policy/AmazonEKS_EFS_CSI_Driver_Policy \
--approve \
--region region-code
helm repo add aws-efs-csi-driver https://kubernetes-sigs.github.io/aws-efs-csi-driver/
2.更新repo
helm repo update
3.hlem安装EFS CSI驱动
helm upgrade -i aws-efs-csi-driver aws-efs-csi-driver/aws-efs-csi-driver \
--namespace kube-system \
--set image.repository=918309763551.dkr.ecr.cn-north-1.amazonaws.com.cn/eks/aws-efs-csi-driver \
--set controller.serviceAccount.create=false \
--set controller.serviceAccount.name=efs-csi-controller-sa
4.StorageClass部署
curl -o storageclass.yaml https://raw.githubusercontent.com/kubernetes-sigs/aws-efs-csi-driver/master/examples/kubernetes/dynamic_provisioning/specs/storageclass.yaml
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" # optional
gidRangeEnd: "2000" # optional
basePath: "/dynamic_provisioning" # optiona
kubectl apply -f storageclass.yaml
1.将eks集群所在VPC、Subnet添加为EFS挂载目标
2.挂载目标的安全组开通入站端口2049,源地址为eks集群所在cidr
官方文档链接参考:
https://docs.amazonaws.cn/eks/latest/userguide/efs-csi.html
https://kubernetes.io/zh-cn/docs/concepts/storage/persistent-volumes/