aboutsummaryrefslogtreecommitdiffstats
path: root/deployment/aks/configure_nfs_pod.sh
blob: 96f66a6f3b9beabb6ab23ea3af106820c50e4b2e (plain)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
# Copyright 2019 AT&T Intellectual Property. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

PRIVATE_KEY=$1
KUBECONFIG=$2
NFS_IP=$3
ADMIN_USER=$4

export KUBECONFIG=$KUBECONFIG

echo "setting up nfs on AKS nodes"
kubectl create configmap aks-key --from-file=$PRIVATE_KEY

for IPADDRESS in `kubectl get nodes -o jsonpath='{.items[*].status.addresses[?(@.type=="InternalIP")].address}'`; do 

cat  <<EOF | kubectl create -f -
apiVersion: v1
kind: Pod
metadata:
  generateName: configure-nfs-
spec:
  containers:
  - name: configure-nfs
    image: alpine
    env:
    - name: IP_ADDRESS
      value: "$IPADDRESS"
    - name: NFS_IP
      value: "$NFS_IP"
    volumeMounts:
    - name: aks-key
      mountPath: /aks-key
    command: ["/bin/sh"]
    args:
      - -c
      - apk update && \
        apk add openssh-client && \
        sh -c "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i /aks-key/id_rsa $ADMIN_USER@\$IP_ADDRESS \"sudo apt-get update; sudo apt-get install nfs-common; sudo rm -rf /dockerdata-nfs; sudo mkdir /dockerdata-nfs; sudo mount -t nfs \$NFS_IP:/dockerdata-nfs /dockerdata-nfs/\""
  restartPolicy: Never
  volumes:
    - name: aks-key
      configMap:
        name: aks-key
        defaultMode: 0600
EOF

done

# TODO
# Add actual pod status check here
echo "sleeping 30 seconds"
sleep 30

kubectl delete configmap aks-key
kubectl get pods | grep configure-nfs | while read line; do
  pod=`echo $line | awk '{print $1}'`
  kubectl delete pod $pod
done