AWS – EKS 安装 EFS CSI插件
EFS和EBS的具体差别是,EFS能够跨zone,而EBS只能部署在单个zone而已,而且一个EBS只能绑定到单台ec2 worker node而已。如果你的EKS的多个worker node在多个不同的zone的话,会比较建议使用EFS作为你的persistent volume选择方案。
【安装EFS CSI – 方法1】
- 使用eksctl为EKS集群创建OIDC,如果已经创建了就无需进行这步骤
//把YourClusterName改成你的EKS集群名
eksctl utils associate-iam-oidc-provider --cluster YourClusterName --approve
2. 使用eksctl创建role和service account
参考文档:https://docs.aws.amazon.com/zh_cn/eks/latest/userguide/efs-csi.html
//把YourClusterName改成你的EKS集群名
export cluster_name=YourClusterName
export role_name=AmazonEKS_EFS_CSI_DriverRole
eksctl create iamserviceaccount \
--name efs-csi-controller-sa \
--namespace kube-system \
--cluster $cluster_name \
--role-name $role_name \
--role-only \
--attach-policy-arn arn:aws:iam::aws:policy/service-role/AmazonEFSCSIDriverPolicy \
--approve
TRUST_POLICY=$(aws iam get-role --role-name $role_name --query 'Role.AssumeRolePolicyDocument' | \
sed -e 's/efs-csi-controller-sa/efs-csi-*/' -e 's/StringEquals/StringLike/')
aws iam update-assume-role-policy --role-name $role_name --policy-document "$TRUST_POLICY"
3. 使用eksctl为eks集群安装EFS CSI插件,并且绑定第二步骤已经创建好的Role
参考文档:https://docs.aws.amazon.com/zh_cn/eks/latest/userguide/managing-add-ons.html#creating-an-add-on
//把YourClusterName改成你的EKS集群名
//把1122233333改成你aws账号ID
eksctl create addon --cluster YourClusterName --name aws-efs-csi-driver --version latest --service-account-role-arn arn:aws:iam::1122233333:role/AmazonEKS_EFS_CSI_DriverRole --force
【安装EFS CSI – 方法2】
这个方式就是通过console的方式最快最方便
- 通过Addon这里安装EFS CSI

2. 选择使用pod identity的权限来授权,可以选择recommend role 无脑创建即可。

【StorageClass 创建绑定到EFS】
- 需要事前创建EFS并且为你的EKS worker node设定好Security Group, 让worker node能够连接到EFS当中 ,创建EFS的教程按这里
- 创建StorageClass绑定到EFS
StorageClass对接EFS的parameter可以参考这文章:https://github.com/kubernetes-sigs/aws-efs-csi-driver/blob/master/docs/README.md
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: efs-custom-storage1
provisioner: efs.csi.aws.com
parameters:
provisioningMode: efs-ap
fileSystemId: fs-92107410 # 你的EFS ID
directoryPerms: "700" # chmod操作权限,700只有读写权限
gid: "33" # WordPress 默认 GID www-data
uid: "33" # WordPress 默认 UID www-data
basePath: "/dp" # 创建的访问点都将从这个基础路径开始
subPathPattern: "${.PVC.namespace}/${.PVC.name}" # 每个 PVC 将有一个唯一的子路径
ensureUniqueDirectory: "true" # 确保每个PVC都有一个唯一的目录。避免多个 PVC 使用相同的目录
reuseAccessPoint: "true" # optional
reclaimPolicy: RetainYAML- EFS的path不能超过100个chars , 所以建议 basePath 不要太长
【常见问题】
- EFS mounting 和 worker node的security group权限必须set好,否则无法正常连上
- EFS的path不能超过100个chars,basePath和subPathPattern的使用尽可能短一点,否则PVC会报错
- subnet优先支持ipv6 但是EKS集群只支持IPv4 ,会造成worker node默认选择使用ipv6,即便是SG权限足够也无法连上EFS
【常用debug方式】
- 使用nslookup 看看是否能够读到mouting节点的ip, 必须和console的一模一样才对,如果subnet默认是关闭了IPv6的话,那么lookup就只会看到ipv4
nslookup fs-xxxxxxx.efs.ap-southeast-1.amazonaws.com

2. 使用telnet看看是否能够连接得上,如果无法连接的话就是Security Group的设定有错了
telnet fs-xxxxxxx.efs.ap-southeast-1.amazonaws.com 2049
【subnet关闭默认IPv6的方法】
在subnnet setting当中以下的两个checkbox必须untick

如果想要EBS CSI方案可以查看这文章:https://www.pangzai.win/aws-eks-%e5%ae%89%e8%a3%85-ebs-csi%e6%8f%92%e4%bb%b6/
Kubernetes存储方案,PV&PVC 可以查看这文章:https://www.pangzai.win/kubernetes-pv-pvc-storageclass%e8%ae%b2%e8%a7%a3/
![]()