blob: 96f66a6f3b9beabb6ab23ea3af106820c50e4b2e [file] [log] [blame]
stark, steven6754bc12019-09-19 15:43:00 -07001#!/bin/bash
2# Copyright 2019 AT&T Intellectual Property. All rights reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16PRIVATE_KEY=$1
17KUBECONFIG=$2
18NFS_IP=$3
19ADMIN_USER=$4
20
21export KUBECONFIG=$KUBECONFIG
22
23echo "setting up nfs on AKS nodes"
24kubectl create configmap aks-key --from-file=$PRIVATE_KEY
25
26for IPADDRESS in `kubectl get nodes -o jsonpath='{.items[*].status.addresses[?(@.type=="InternalIP")].address}'`; do
27
28cat <<EOF | kubectl create -f -
29apiVersion: v1
30kind: Pod
31metadata:
32 generateName: configure-nfs-
33spec:
34 containers:
35 - name: configure-nfs
36 image: alpine
37 env:
38 - name: IP_ADDRESS
39 value: "$IPADDRESS"
40 - name: NFS_IP
41 value: "$NFS_IP"
42 volumeMounts:
43 - name: aks-key
44 mountPath: /aks-key
45 command: ["/bin/sh"]
46 args:
47 - -c
48 - apk update && \
49 apk add openssh-client && \
50 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/\""
51 restartPolicy: Never
52 volumes:
53 - name: aks-key
54 configMap:
55 name: aks-key
56 defaultMode: 0600
57EOF
58
59done
60
61# TODO
62# Add actual pod status check here
63echo "sleeping 30 seconds"
64sleep 30
65
66kubectl delete configmap aks-key
67kubectl get pods | grep configure-nfs | while read line; do
68 pod=`echo $line | awk '{print $1}'`
69 kubectl delete pod $pod
70done