Use Hostname instead of IP to install k8s
[iec.git] / src / foundation / scripts / helm.sh
1 #!/bin/bash -ex
2
3 if [ -f "$HOME/.bashrc" ]; then
4   # shellcheck source=/dev/null
5   source "$HOME/.bashrc"
6 fi
7
8 VERSION='v2.12.3'
9 TILLER_SA_RBAC=~/tiller-rbac.yaml
10 if [ "$(uname -m)" == 'aarch64' ]; then
11   FLAVOR='linux-arm64'
12 else
13   FLAVOR='linux-amd64'
14 fi
15
16 URI_ROOT='https://storage.googleapis.com/kubernetes-helm'
17 TGZ_NAME="helm-${VERSION}-${FLAVOR}.tar.gz"
18
19 if [ ! -e /usr/bin/helm ] || [ ! -e /usr/bin/tiller ]; then
20   wget -O "/tmp/${TGZ_NAME}" "${URI_ROOT}/${TGZ_NAME}"
21   sudo tar xpPf "/tmp/${TGZ_NAME}" --overwrite \
22     --transform "s|${FLAVOR}|/usr/bin|" "${FLAVOR}/"{helm,tiller}
23   rm -f "/tmp/${TGZ_NAME}"
24 fi
25
26 if ! kubectl get serviceaccounts --namespace=kube-system | grep -q tiller; then
27   cat <<EOF > "${TILLER_SA_RBAC}"
28 apiVersion: v1
29 kind: ServiceAccount
30 metadata:
31   name: tiller
32   namespace: kube-system
33 ---
34 apiVersion: rbac.authorization.k8s.io/v1
35 kind: ClusterRoleBinding
36 metadata:
37   name: tiller
38 roleRef:
39   apiGroup: rbac.authorization.k8s.io
40   kind: ClusterRole
41   name: cluster-admin
42 subjects:
43   - kind: ServiceAccount
44     name: tiller
45     namespace: kube-system
46 EOF
47   kubectl create -f "${TILLER_SA_RBAC}"
48   helm init --service-account tiller --tiller-image="jessestuart/tiller:${VERSION}"
49 fi
50 rm -f "${TILLER_SA_RBAC}"