Re-org the IEC repo to adapt to actual deployment
[iec.git] / src / foundation / scripts / nginx.sh
diff --git a/src/foundation/scripts/nginx.sh b/src/foundation/scripts/nginx.sh
new file mode 100755 (executable)
index 0000000..40a9377
--- /dev/null
@@ -0,0 +1,64 @@
+#!/bin/bash -ex
+
+NGINX_APP=~/nginx-app.yaml
+
+cat <<EOF > "${NGINX_APP}"
+apiVersion: v1
+kind: Service
+metadata:
+  name: nginx
+  labels:
+    app: nginx
+spec:
+  type: NodePort
+  ports:
+  - port: 80
+    protocol: TCP
+    name: http
+  selector:
+    app: nginx
+---
+apiVersion: v1
+kind: ReplicationController
+metadata:
+  name: nginx
+spec:
+  replicas: 2
+  template:
+    metadata:
+      labels:
+        app: nginx
+    spec:
+      containers:
+      - name: nginx
+        image: nginx
+        ports:
+        - containerPort: 80
+EOF
+
+if ! kubectl get services | grep -q nginx; then
+  kubectl create -f "${NGINX_APP}"
+fi
+kubectl get nodes
+kubectl get services
+kubectl get pods
+kubectl get rc
+
+attempts=60
+while [ $attempts -gt 0 ]
+do
+  if [ 3 == "$(kubectl get pods | grep -c -e STATUS -e Running)" ]; then
+    break
+  fi
+  ((attempts-=1))
+  sleep 10
+done
+[ $attempts -gt 0 ] || exit 1
+
+svcip=$(kubectl get services nginx  -o json | grep clusterIP | cut -f4 -d'"')
+sleep 10
+wget "http://$svcip"
+kubectl delete -f "${NGINX_APP}"
+kubectl get rc
+kubectl get pods
+kubectl get services