-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathk8smaster.sh
65 lines (54 loc) · 2.28 KB
/
k8smaster.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
#!/bin/bash
#
# Kubernetes Master Installation
#
HOME=/home/ubuntu
# obsolet durch Container Cache
# sudo kubeadm config images pull
# wenn WireGuard installiert - Wireguard IP als K8s IP verwenden
export ADDR=$(ip -f inet addr show wg0 | grep -Po 'inet \K[\d.]+')
if [ -f kubeadm.yaml ]
then
sudo kubeadm init --config kubeadm.yaml
else
if [ "${ADDR}" != "" ]
then
sudo kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address ${ADDR} --apiserver-cert-extra-sans $(hostname -f)
else
sudo kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address $(hostname -I | cut -d ' ' -f 1) --apiserver-cert-extra-sans $(hostname -f)
fi
fi
sudo mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown -R ubuntu:ubuntu $HOME/.kube
# aus Kompatilitaet zur Vagrant Installation
sudo mkdir -p /home/vagrant/.kube
sudo cp -i /etc/kubernetes/admin.conf /home/vagrant/.kube/config
sudo chmod 644 /home/vagrant/.kube/config
# this for loop waits until kubectl can access the api server that kubeadm has created
for i in {1..150}; do # timeout for 5 minutes
kubectl get pods &> /dev/null
if [ $? -ne 1 ]; then
break
fi
sleep 2
done
# Pods auf Master Node erlauben
kubectl taint nodes --all node-role.kubernetes.io/master-
# Internes Pods Netzwerk (mit: --iface enp0s8, weil vagrant bei Hostonly Adapters gleiche IP vergibt)
sudo sysctl net.bridge.bridge-nf-call-iptables=1
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
# Standard Persistent Volume und Claim
kubectl apply -f https://raw.githubusercontent.com/mc-b/lerncloud/master/data/DataVolume.yaml
# Join Command fuer Worker Nodes
if [ "${ADDR}" != "" ]
then
# Replace WireGuard IP mit FQDN, sonst wird auf dem VPN zuviel Traffic erzeugt.
sudo kubeadm token create --print-join-command | sed "s/${ADDR}/$(hostname -f)/g" >/data/join-$(hostname).sh
else
sudo kubeadm token create --print-join-command >/data/join-$(hostname).sh
fi
##########################
# Package Manager (HELM - Achtung bei Versionwechsel auch client.sh aendern).
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
helm repo add stable https://charts.helm.sh/stable