-
Notifications
You must be signed in to change notification settings - Fork 1
/
rancher-install.sh
executable file
·131 lines (114 loc) · 3.42 KB
/
rancher-install.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
set -o xtrace
export RANCHER_TLS_SOURCE=rancher
export RANCHER_VERSION=""
export RANCHER_HOSTNAME=""
while test $# -gt 0; do
case "$1" in
-h|--help)
echo "rancher-install.sh - install Rancher from helm chart into RKE lab"
echo " "
echo "rancher-install.sh [options]"
echo " "
echo "options:"
echo "-h, --help show help"
echo "-H, --hostname=HOSTNAME specify hostname for Rancher"
echo "-v, --version=VERSION specify version for Rancher"
echo "-t, --tls-source=SOURCE specify tls source for Rancher ingress rancher/letsEncrypt/secret (defaults to rancher)"
exit 0
;;
-H)
shift
if test $# -gt 0; then
export RANCHER_HOSTNAME=$1
else
echo "no Rancher hostname specified"
exit 1
fi
shift
;;
--hostname*)
export RANCHER_HOSTNAME=`echo $1 | sed -e 's/^[^=]*=//g'`
shift
;;
-v)
shift
if test $# -gt 0; then
export RANCHER_VERSION=$1
else
echo "no Rancher version specified"
exit 1
fi
shift
;;
--version*)
export RANCHER_VERSION=`echo $1 | sed -e 's/^[^=]*=//g'`
shift
;;
-t)
shift
if test $# -gt 0; then
export RANCHER_TLS_SOURCE=$1
else
echo "no Rancher tls source specified"
exit 1
fi
shift
;;
--tls-source*)
export RANCHER_TLS_SOURCE=`echo $1 | sed -e 's/^[^=]*=//g'`
shift
;;
*)
break
;;
esac
done
if [[ $RANCHER_HOSTNAME == "" ]]; then
echo "no Rancher hostname specified"
exit 1
fi
if [[ $RANCHER_VERSION == "" ]]; then
export RANCHER_VERSION_STRING=""
else
export RANCHER_VERSION_STRING="--version $RANCHER_VERSION"
fi
if [[ $RANCHER_TLS_SOURCE == "letsEncrypt" ]]; then
export RANCHER_TLS_STRING="--set ingress.tls.source=letsEncrypt"
elif [[ $RANCHER_TLS_SOURCE == "rancher" ]]; then
export RANCHER_TLS_STRING=""
elif [[ $RANCHER_TLS_SOURCE == "secret" ]]; then
export RANCHER_TLS_STRING="--set ingress.tls.source=secret"
else
echo "Invalid tls source specified, must be one of rancher/letsEncrypt/secret"
exit 1
fi
export KUBECONFIG=kube_config_cluster.yml
helm repo add rancher-stable https://releases.rancher.com/server-charts/stable
kubectl rollout status daemonset -n ingress-nginx nginx-ingress-controller
if [[ $RANCHER_TLS_SOURCE == "rancher" || $RANCHER_TLS_SOURCE == "letsEncrypt" ]]; then
helm repo add jetstack https://charts.jetstack.io
helm repo update
helm upgrade --install cert-manager jetstack/cert-manager \
--namespace cert-manager \
--create-namespace \
--version v1.5.1 \
--set installCRDs=true
kubectl wait --for=condition=Available -n cert-manager deployment cert-manager-webhook
helm upgrade --install rancher rancher-stable/rancher \
--namespace cattle-system \
--create-namespace \
--set hostname=$RANCHER_HOSTNAME \
$RANCHER_TLS_STRING \
$RANCHER_VERSION_STRING
else
kubectl create namespace cattle-system
kubectl -n cattle-system create secret generic tls-ca --from-file=./certs/cacerts.pem
kubectl -n cattle-system create secret tls tls-rancher-ingress --cert=./certs/cert.pem --key=./certs/key.pem
helm install rancher rancher-stable/rancher \
--namespace cattle-system \
--set hostname=$RANCHER_HOSTNAME \
$RANCHER_VERSION_STRING \
$RANCHER_TLS_STRING \
--set privateCA=true
fi