K8S Verify script added 69/869/1
authorabhijit_onap <abhijit.das.gupta@huawei.com>
Tue, 28 May 2019 13:36:42 +0000 (13:36 +0000)
committerabhijit_onap <abhijit.das.gupta@huawei.com>
Tue, 28 May 2019 13:38:22 +0000 (13:38 +0000)
Signed-off-by: abhijit_onap <abhijit.das.gupta@huawei.com>
Change-Id: I9c3c1d46879a1da882c63fd7c12e5a2aabdb2d5f

scripts/verifyk8s.sh [new file with mode: 0755]

diff --git a/scripts/verifyk8s.sh b/scripts/verifyk8s.sh
new file mode 100755 (executable)
index 0000000..db21afd
--- /dev/null
@@ -0,0 +1,54 @@
+#!/bin/bash -ex
+##############################################################################
+# Copyright (c) 2019 Huawei Tech and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+NGINXDEP=~/testk8s-nginx.yaml
+
+cat <<EOF > "${NGINXDEP}"
+---
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: nginx-deployment
+  labels:
+    app: nginx
+spec:
+  replicas: 1
+  selector:
+    matchLabels:
+      app: nginx
+  template:
+    metadata:
+      labels:
+        app: nginx
+    spec:
+      containers:
+        - name: nginx
+          image: nginx:1.15.12
+          ports:
+        - containerPort: 80
+          hostPort: 80
+EOF
+
+#check if nginx is already deployed
+if ! kubectl get pods | grep nginx; then
+  kubectl create -f testk8snginx.yaml
+fi
+
+#To check whether the deployment is succesesfull
+retry=10
+while [ $retry -gt 0 ]
+do
+  if [ 2 == "$(kubectl get pods | grep -c -e STATUS -e Running)" ]; then
+    break
+  fi
+  ((retry-=1)) 
+  sleep 10
+done
+[ $retry -gt 0 ] || exit 1