forked from PureStorage-OpenConnect/TestDriveNewStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstallKubernetes.sh
More file actions
executable file
·132 lines (103 loc) · 3.91 KB
/
installKubernetes.sh
File metadata and controls
executable file
·132 lines (103 loc) · 3.91 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env bash
set -o pipefail
echo " "
echo "#### Clone kubespray repo and copy inventory in to repo ####"
git clone https://github.com/kubernetes-sigs/kubespray ~/kubespray
# Move inventory and other kubespray variables in to place
cp -rfv ~/TestDriveNewStack/resources/kubernetes/inventory/testdrive ~/kubespray/inventory/
# Install prereqs as we now have pip3
echo " "
echo "#### Install kubespray prereqs ####"
pip3 install -r ~/kubespray/requirements.txt
# Install kubernetes
echo " "
echo "#### Install kubernetes ####"
function runInstallKub() {
inventoryFile="$HOME/kubespray/inventory/testdrive/inventory.ini"
clusterFile="$HOME/kubespray/cluster.yml"
#run the playbook
if [[ -f $inventoryFile && -f $clusterFile ]];then
$(cd $HOME/kubespray/)
ansible-playbook -i ${inventoryFile} ${clusterFile} -b
else
echo "Please check to make sure that $inventoryFile and $clusterFile exist."
fi
}
runInstallKub
echo " "
echo "#### Install snapshot providers ####"
# install CRD with Beta release
kubectl create -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/release-2.0/config/crd/snapshot.storage.k8s.io_volumesnapshotclasses.yaml
kubectl create -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/release-2.0/config/crd/snapshot.storage.k8s.io_volumesnapshotcontents.yaml
kubectl create -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/release-2.0/config/crd/snapshot.storage.k8s.io_volumesnapshots.yaml
#Add the snap controller
kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/release-2.0/deploy/kubernetes/snapshot-controller/rbac-snapshot-controller.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/release-2.0/deploy/kubernetes/snapshot-controller/setup-snapshot-controller.yaml
function getSnap() {
kubectl get pods snapshot-controller-0 2>&1 > /dev/null
}
function checkSnap() {
count=0
tries=10
while [[ $count != $tries ]];do
getSnap
if [[ $? -eq 0 ]];then
echo "Snapshotter appears to be up..."
break
else
echo "Waiting on the snapshotter."
((count++))
sleep 2
fi
done
if [[ $count -eq $tries ]];then
echo "Check on the snapshotter, moving on."
fi
}
checkSnap
#Install PSO
echo " "
echo "#### Update helm repos and install PSO ####"
helm repo add pure https://purestorage.github.io/pso-csi
helm repo update
helm install pure-storage-driver pure/pure-pso --version 6.0.1 --namespace default -f ~/TestDriveNewStack/resources/kubernetes/pso_values.yaml
#Check to make sure that PSO controller is up and 'READY'
function psoChecker() {
count=0
tries=60
while [[ $count != $tries ]]; do
have=$(kubectl get pods pso-csi-controller-0 |awk '{if(NR>1)print $2}'|awk -F'/' '{print $1}')
want=$(kubectl get pods pso-csi-controller-0 |awk '{if(NR>1)print $2}'|awk -F'/' '{print $2}')
if [[ $have == 0 ]];then
echo "Waiting for PSO. $have up vs $want desired. $count out of $tries tries."
((count++))
sleep 2
elif [[ $have != 0 && $have -lt $want ]];then
echo "Waiting for PSO. $have up vs $want desired. $count out of $tries tries."
((count++))
sleep 2
elif [[ $have != 0 && $have == $want ]];then
echo " "
echo "#########################################"
echo " "
break
fi
done
}
psoChecker
#Install the purestorage snapshot class
kubectl apply -f https://raw.githubusercontent.com/purestorage/pso-csi/master/pure-pso/snapshotclass.yaml
echo " "
echo "#### Changing hostname ####"
# Fix the hostname as the case doesn't match the flasharray in testdrive.
# This is only needed for ansible playbooks
echo "linux" > /etc/hostname
systemctl restart systemd-hostnamed
sleep 3
#Let's add autocompletion and a shortcut for kubectl
export KUBECONFIG=$HOME/.admin.conf
alias k="kubectl"
source <(kubectl completion bash)
complete -F __start_kubectl k
echo " "
echo "Kubernetes Setup Complete"