-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-k8s
executable file
·186 lines (148 loc) · 5.53 KB
/
install-k8s
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/bin/bash
START_TIME=$SECONDS
function pak {
if [ ! -z "$PAUSE" ]; then
read -p "Press any key to continue...";
fi
}
function msg () {
echo "--"
echo "-- $1"
echo "--"
}
if [[ "$1" == "-p" ]]; then PAUSE="yes"; fi
ALL='k8s-master k8s-worker1 k8s-worker2'
for m in $ALL; do
msg "Testing conectivity to $m"
echo ssh root@${m} w
ssh root@${m} w
done
pak
for m in $ALL; do
msg "Initial configuration of $m"
ssh root@${m} "
sed -i '/swap/d' /etc/fstab
swapoff -a
echo 'overlay' >> /etc/modules-load.d/containerd.conf
echo 'br_netfilter' >> /etc/modules-load.d/containerd.conf
modprobe overlay
modprobe br_netfilter
echo 'net.bridge.bridge-nf-call-ip6tables = 1' >> /etc/sysctl.d/kubernetes.conf
echo 'net.bridge.bridge-nf-call-iptables = 1' >> /etc/sysctl.d/kubernetes.conf
echo 'net.ipv4.ip_forward = 1' >> /etc/sysctl.d/kubernetes.conf
sysctl --system
"
#pak
msg "Step 3) Install containerd run time"
echo ssh root@${m} 'apt install -y curl gnupg2 software-properties-common apt-transport-https ca-certificates'
ssh root@${m} 'apt install -y curl gnupg2 software-properties-common apt-transport-https ca-certificates'
#pak
echo ssh root@${m} 'curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor | tee /etc/apt/trusted.gpg.d/docker.gpg > /dev/null'
#ssh root@${m} 'curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/trusted.gpg.d/docker.gpg'
# See: https://gist.github.com/notpushkin/1cbdd3cbab0cf3570f87b7f2c0cb852d
ssh root@${m} 'curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor | tee /etc/apt/trusted.gpg.d/docker.gpg > /dev/null'
#pak
echo ssh root@${m} 'add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"'
ssh root@${m} 'add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"'
#pak
echo ssh root@${m} 'apt update'
ssh root@${m} 'apt update'
#pak
echo ssh root@${m} 'apt install -y containerd.io'
ssh root@${m} 'apt install -y containerd.io'
#pak
echo ssh root@${m} 'containerd config default | tee /etc/containerd/config.toml >/dev/null 2>&1'
ssh root@${m} 'containerd config default | tee /etc/containerd/config.toml >/dev/null 2>&1'
#pak
echo ssh root@${m} "sed -i 's/SystemdCgroup \= false/SystemdCgroup \= true/g' /etc/containerd/config.toml"
ssh root@${m} "sed -i 's/SystemdCgroup \= false/SystemdCgroup \= true/g' /etc/containerd/config.toml"
#pak
echo ssh root@${m} 'systemctl restart containerd'
ssh root@${m} 'systemctl restart containerd'
#pak
echo ssh root@${m} 'systemctl enable containerd'
ssh root@${m} 'systemctl enable containerd'
pak
done
for m in $ALL; do
msg "Step 4) Add apt repository for Kubernetes ($m)"
ssh root@${m} "
curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | gpg --dearmor | tee /etc/apt/trusted.gpg.d/k8s.gpg > /dev/null
#curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
apt-add-repository 'deb http://apt.kubernetes.io/ kubernetes-xenial main'
"
msg "Step 5) Install Kubernetes components Kubectl, kubeadm & kubelet ($m)"
ssh root@${m} "
apt update
apt install -y kubelet kubeadm kubectl
apt-mark hold kubelet kubeadm kubectl
"
pak
done
msg "Step 6) Initialize Kubernetes cluster with Kubeadm command (k8s-master)"
msg " Downloading images..."
pak
ssh root@k8s-master "kubeadm config images pull"
msg " Executing kubeadm init on master node..."
ssh root@k8s-master "
kubeadm init --control-plane-endpoint=10.10.10.10
mkdir -p \$HOME/.kube
cp -i /etc/kubernetes/admin.conf \$HOME/.kube/config
chown \$(id -u):\$(id -g) \$HOME/.kube/config
kubectl cluster-info
kubectl get nodes
"
pak
JOINCMD=$( ssh root@k8s-master "kubeadm token create --print-join-command" )
echo $JOINCMD
pak
msg "Adding worker1..."
ssh root@k8s-worker1 "$JOINCMD"
pak
msg "Adding worker2..."
ssh root@k8s-worker2 "$JOINCMD"
pak
ssh root@k8s-master "kubectl get nodes"
pak
msg "Step 6) Install Calico Pod Network Add-on"
# curl https://projectcalico.docs.tigera.io/manifests/calico.yaml -O
# kubectl apply -f calico.yaml
ssh root@k8s-master "
kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.25.0/manifests/calico.yaml
kubectl set env daemonset/calico-node -n kube-system IP_AUTODETECTION_METHOD=interface=eth1
"
sleep 30
ssh root@k8s-master "kubectl get pods -n kube-system"
pak
msg "Step 7) Install Multus"
ssh root@k8s-master "
mkdir -p k8s
cd k8s
git clone https://github.com/k8snetworkplumbingwg/multus-cni.git
cd multus-cni
cat ./deployments/multus-daemonset-thick.yml | kubectl apply -f -
sleep 10
kubectl get pods --all-namespaces | grep -i multus
"
pak
msg "Step 8) Install Ingress NGINX"
ssh root@k8s-master "
cd k8s/
wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.5.1/deploy/static/provider/baremetal/deploy.yaml
sed -i 's/NodePort/LoadBalancer/' deploy.yaml
kubectl apply -f deploy.yaml
kubectl get pods -n ingress-nginx
"
pak
msg "Step 9) Install MetalLB"
ssh root@k8s-master "
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.13.7/config/manifests/metallb-native.yaml
sleep 20
kubectl apply -f k8s/config-pool.yaml
kubectl apply -f k8s/config-l2adv.yaml
kubectl get all -n metallb-system
"
ELAPSED_TIME=$(($SECONDS - $START_TIME))
echo "--"
echo "-- K8s installed in $ELAPSED_TIME seconds"
echo "--"