-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·105 lines (80 loc) · 2.97 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·105 lines (80 loc) · 2.97 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
#!/bin/bash
# See https://kubernetes.github.io/ingress-nginx/deploy/#quick-start
# and https://kubernetes.io/docs/tasks/access-application-cluster/ingress-minikube/
set -euxo pipefail
DIR=$(cd "$(dirname "$0")"; pwd -P)
. $DIR/conf.sh
usage() {
cat << EOD
Usage: `basename $0` [options]
Available options:
-h this message
-s run exercice and solution
Run ingress exercice
EOD
}
INGRESS_FULL=false
# get the options
while getopts hs c ; do
case $c in
h) usage ; exit 0 ;;
s) INGRESS_FULL=true ;;
\?) usage ; exit 2 ;;
esac
done
shift `expr $OPTIND - 1`
if [ $# -ne 0 ] ; then
usage
exit 2
fi
NSAPP="ingress-app"
NODE1_IP=$(kubectl get nodes --selector="! node-role.kubernetes.io/master" \
-o=jsonpath='{.items[0].status.addresses[0].address}')
# Run on kubeadm cluster
# see "kubernetes in action" p391
kubectl delete ns -l "ingress=nginx"
kubectl create namespace "$ingress_ns"
kubectl create namespace "$NSAPP"
kubectl label ns "$ingress_ns" "ingress=nginx"
kubectl label ns "$NSAPP" "ingress=nginx"
ink "Install nginx-controller"
helm upgrade --install ingress-nginx ingress-nginx \
--repo https://kubernetes.github.io/ingress-nginx \
--namespace "$ingress_ns" --create-namespace
ink "Deploy application"
kubectl create deployment web -n "$NSAPP" --image=gcr.io/google-samples/hello-app:1.0
kubectl expose deployment web -n "$NSAPP" --port=8080
kubectl wait -n "$NSAPP" --for=condition=available deployment web
ink "Wait for nginx-controller to be up and running (alternatively, use helm --wait)"
kubectl wait --for=condition=available deployment -n "$ingress_ns" -l app.kubernetes.io/instance=ingress-nginx
TMP_STR="$NODE1_IP hello-world.info"
echo "INFO: Add '$TMP_STR' to /etc/hosts"
sudo sh -c "echo '$TMP_STR' >> /etc/hosts"
if [ "$INGRESS_FULL" = false ]
then
exit 0
fi
ink "Generate self-signed certificates for HTTPS"
$DIR/generate-certs.sh hello-world.info
ink "Create TLS secret from generated certificates"
kubectl create secret tls hello-world-tls -n "$NSAPP" \
--key $DIR/certs/tls.key \
--cert $DIR/certs/tls.crt
ink "Create ingress route with TLS"
kubectl apply -n "$NSAPP" -f $DIR/example-ingress.yaml
kubectl get -n "$NSAPP" ingress
ink "Access the application"
NODE_PORT=$(kubectl get svc ingress-nginx-controller -n "$ingress_ns" -o jsonpath="{.spec.ports[0].nodePort}")
helm upgrade --wait --install ingress-nginx ingress-nginx \
--repo https://kubernetes.github.io/ingress-nginx \
--namespace "$ingress_ns" --create-namespace \
--set controller.service.type=NodePort
HTTPS_NODE_PORT=$(kubectl get svc ingress-nginx-controller -n "$ingress_ns" -o jsonpath="{.spec.ports[1].nodePort}")
echo "INFO: access the application via ingress"
echo "HTTP: curl hello-world.info:$NODE_PORT"
echo "HTTPS: curl -k https://hello-world.info:$HTTPS_NODE_PORT"
echo ""
curl hello-world.info:$NODE_PORT
echo ""
echo "Testing HTTPS endpoint (ignoring self-signed certificate):"
curl -k https://hello-world.info:$HTTPS_NODE_PORT