install-efs-provisioner.sh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/bin/bash
  2. WORK_DIR=$(dirname $0)
  3. source ${WORK_DIR}/efs-env
  4. install_efs_provisioner()
  5. {
  6. # Add efs-provistioner Helm Chart
  7. helm repo add efs-provisioner https://charts.helm.sh/stable
  8. # Get EKS security group
  9. which aws > /dev/null
  10. if [[ $? -eq 0 ]] && [[ -n "$EKS_NAME" ]] && [[ -n "$EFS_SECURITY_GROUPS" ]]
  11. then
  12. echo "aws eks describe-cluster "
  13. echo " --name $EKS_NAME"
  14. echo " --region $EFS_REGION"
  15. echo " --query cluster.resourcesVpcConfig.clusterSecurityGroupId"
  16. eks_security_group_id=$(aws eks describe-cluster \
  17. --name $EKS_NAME \
  18. --region $EFS_REGION \
  19. --query cluster.resourcesVpcConfig.clusterSecurityGroupId)
  20. if [[ -z $eks_security_group_id ]]
  21. then
  22. echo "Cannot find EKS scurity group id with AWS profile $AWS_PROFILE,"
  23. echo "EKS name $EKS_NAME in region $EFS_REGSION"
  24. exit 1
  25. fi
  26. echo "EKS security gorup id: $eks_security_group_id"
  27. # Authorize inbound access to the EKS security groups for EFS mount targets
  28. for group_id in ${EFS_SECURITY_GROUPS}
  29. do
  30. echo "aws ec2 authorize-security-group-ingress"
  31. echo " --group-id $group_id"
  32. echo " --protocol tcp"
  33. echo " --port 2049"
  34. echo " --source-group $eks_security_group_id"
  35. echo " --region $AWS_REGION"
  36. aws ec2 authorize-security-group-ingress \
  37. --group-id $group_id \
  38. --protocol tcp \
  39. --port 2049 \
  40. --source-group $eks_security_group_id --region $EFS_REGION
  41. done
  42. fi
  43. # create efs-provisiner
  44. if [[ "${EFS_CSI_DRIVER}" == "true" ]]
  45. then
  46. echo "kubectl apply -k \"github.com/kubernetes-sigs/aws-efs-csi-driver/deploy/kubernetes/overlays/stable/ecr/?ref=release-1.0\""
  47. kubectl apply -k "github.com/kubernetes-sigs/aws-efs-csi-driver/deploy/kubernetes/overlays/stable/ecr/?ref=release-1.0"
  48. fi
  49. helm install ${EFS_NAME} \
  50. efs-provisioner/efs-provisioner \
  51. --set efsProvisioner.efsFileSystemId=${EFS_ID} \
  52. --set efsProvisioner.awsRegion=${EFS_REGION} \
  53. --set efsProvisioner.storageClass.reclaimPolicy=${RECLAIM_POLICY}
  54. }
  55. helm list | grep -q ${EFS_NAME}
  56. if [[ $? -ne 0 ]]
  57. then
  58. install_efs_provisioner
  59. else
  60. echo "efs-provisioner $EFS_NAME may already exists."
  61. fi