3e419b94b030f13b3f649b35d81a1f4b47998660
[iec.git] / src / foundation / scripts / nginx.sh
1 #!/bin/bash -ex
2
3 NGINX_APP=~/nginx-app.yaml
4
5 cat <<EOF > "${NGINX_APP}"
6 apiVersion: v1
7 kind: Service
8 metadata:
9   name: nginx
10   labels:
11     app: nginx
12 spec:
13   type: NodePort
14   ports:
15   - port: 80
16     protocol: TCP
17     name: http
18   selector:
19     app: nginx
20 ---
21 apiVersion: v1
22 kind: ReplicationController
23 metadata:
24   name: nginx
25 spec:
26   replicas: 2
27   template:
28     metadata:
29       labels:
30         app: nginx
31     spec:
32       containers:
33       - name: nginx
34         image: nginx
35         ports:
36         - containerPort: 80
37 EOF
38
39 if [ -f "$HOME/.bashrc" ]; then
40   # shellcheck source=/dev/null
41   source "$HOME/.bashrc"
42 fi
43
44 if ! kubectl get services | grep -q nginx; then
45   kubectl create -f "${NGINX_APP}"
46 fi
47 kubectl get nodes
48 kubectl get services
49 kubectl get pods
50 kubectl get rc
51
52 attempts=60
53 while [ $attempts -gt 0 ]
54 do
55   if [ 3 == "$(kubectl get pods | grep -c -e STATUS -e Running)" ]; then
56     break
57   fi
58   ((attempts-=1))
59   sleep 10
60 done
61 [ $attempts -gt 0 ] || exit 1
62
63 svcip=$(kubectl get services nginx  -o json | grep clusterIP | cut -f4 -d'"')
64 sleep 10
65 wget -O /dev/null "http://$svcip"
66 kubectl delete -f "${NGINX_APP}"
67 rm -f "${NGINX_APP}"
68 kubectl get rc
69 kubectl get pods
70 kubectl get services