-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.sh
executable file
·89 lines (72 loc) · 2.39 KB
/
start.sh
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
#!/bin/sh
IMAGE=mkenney/k8s-proxy:latest
DEPLOYMENT=k8s-proxy
k8s_context=$(kubectl config view -o=jsonpath='{.current-context}')
WARN=$'\033[38;5;1m'
EMPH=$'\033[38;5;172m'
NORM=$'\033[0m'
printf "
This script will start the kubernetes proxy service using the \`kubectl apply\`
command.
${WARN}Please make sure you are configured for the intended environment${NORM}
Current context: ${EMPH}${k8s_context}${NORM}
"
read -p "Do you want to continue? [y/N]: " EXECUTE
if [ "y" != "$EXECUTE" ] && [ "Y" != "$EXECUTE" ]; then
exit 0
fi
printf "
Starting the k8s-proxy service.
The \`k8s-proxy\` service will serve all traffic on ports 80 and 443.
SSL traffic is terminated using a self-signed certificate with the
associated issues. Ports are not configurable via this script but can be
changed in \`k8s-proxy.yml\`. You must set both the exposed ports in the
deployment and service as well as the PORT and SECUREPORT environment
variables in the deployment. Exposing the ports allows them to receive
traffic and defining the environment variables tells the proxy serice
which ports to listen on.
Not for production use.
"
if [ "build" = "$1" ] || [ "--build" = "$1" ]; then
echo "building image..."
docker build -t $IMAGE . &> /dev/null
exit_code=$?
if [ "0" != "$exit_code" ]; then
echo " building image '$IMAGE' failed"
exit $exit_code
fi
fi
echo "removing k8s-proxy deployment and service..."
kubectl delete deploy k8s-proxy &> /dev/null
kubectl delete service k8s-proxy &> /dev/null
kubectl delete ingress k8s-proxy &> /dev/null
echo "applying k8s-proxy deployment and service..."
kubectl apply -f k8s-proxy.yml > /dev/null
pod=
printf "\n"
trycount=0
while [ ! -n "$pod" ] && [ "60" -gt "$trycount" ]; do
sleep 1
pod=$(kubectl get po | grep 'k8s-proxy' | grep -i running | grep '1/1' | grep -v 'k8s-proxy-test' | awk '{print $1}')
printf "."
((trycount+=1))
done
printf "\n"
echo
echo "Service:"
echo "$(kubectl get service | egrep '(k8s-proxy)|(NAME)')"
echo
echo "Deployment:"
echo "$(kubectl get deploy | egrep '(k8s-proxy)|(NAME)')"
echo
echo "Pods:"
echo "$(kubectl get po | egrep '(k8s-proxy)|(NAME)' | grep -v Terminating)"
echo
if [ "" = "$pod" ]; then
echo "Timed out waiting for pod to be ready"
exit 0
fi
# hide the readiness/liveness probe noise...
echo "kubectl logs -f $pod | grep -v 'probe OK'"
echo
kubectl logs -f $pod | grep -v 'probe OK'