-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-pv.sh
executable file
·42 lines (36 loc) · 1.13 KB
/
create-pv.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
set -e
CLUSTER=aws.kazoku.co
ZONE=us-east-1
SUBNETS=(subnet-ab591c86 subnet-eb6943a2 subnet-1a088f26 subnet-d3413288)
SECGROUPS="--security-groups=sg-4bfa2037 --security-groups=sg-44fa2038"
FSID=$(aws --output=text --query=FileSystemId efs create-file-system --creation-token=$(openssl rand -hex 32))
echo "created: $FSID"
STATE="creating"
until [[ ${STATE} == "available" ]]; do
echo "-- waiting (state=${STATE})"
STATE=$(aws --output=text --query=FileSystems[0].LifeCycleState efs describe-file-systems --file-system-id=${FSID})
sleep 1
done
aws efs create-tags --file-system-id=${FSID} --tags="Key=KubernetesCluster,Value=${CLUSTER}"
for subnet in ${SUBNETS[@]}; do
aws efs --output=json create-mount-target --file-system-id=${FSID} --subnet-id=${subnet} ${SECGROUPS}
done
kubectl create -f - <<EOF
apiVersion: v1
kind: PersistentVolume
metadata:
name: ${FSID}
annotations:
volume.beta.kubernetes.io/storage-class: "slow"
spec:
capacity:
storage: 1000Gi
accessModes:
- ReadWriteMany
- ReadOnlyMany
persistentVolumeReclaimPolicy: Recycle
nfs:
path: /
server: ${FSID}.efs.${ZONE}.amazonaws.com
EOF