-
Notifications
You must be signed in to change notification settings - Fork 1
/
install_k8s.sh
executable file
·85 lines (56 loc) · 2.49 KB
/
install_k8s.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
#!/bin/bash
tput setaf 2 && echo installing k8s master node... && tput setaf 7
ufw disable && swapoff -a && sed -i 's/^\/swap/#\/swap/' /etc/fstab
cat <<EOT > /etc/modules-load.d/k8s.conf
br_netfilter
overlay
EOT
modprobe br_netfilter && modprobe overlay
iptables -I INPUT 1 -p tcp --match multiport --dports 6443,2379:2380,10250:10252 -j ACCEPT
echo iptables-persistent iptables-persistent/autosave_v4 boolean true | sudo debconf-set-selections
echo iptables-persistent iptables-persistent/autosave_v6 boolean true | sudo debconf-set-selections
apt-get -y install iptables-persistent
netfilter-persistent save
cat <<EOT >> /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2",
"storage-opts": [
"overlay2.override_kernel_check=true"
]
}
EOT
cat <<EOT > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOT
sysctl --system
apt-get update && apt-get install -y apt-transport-https
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | tee -a /etc/apt/sources.list.d/kubernetes.list
#apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"
apt-get update && apt-get install -y kubelet kubeadm kubectl
service docker restart
# this 2 lines remove the bug "Unimplemented desc = unknown service runtime.v1alpha2.ImageService"
# for k8s version > 1.19.*, containerd.io > 1.3.*, os = ubuntu 20.04
rm /etc/containerd/config.toml
systemctl restart containerd
kubeadm config images pull
tput setaf 2 && echo "init kube .. pod-network: 10.244.0.0/16" && tput setaf 7
kubeadm init --pod-network-cidr=10.244.0.0/16
tput setaf 2 && echo "start set up vars, alias and kubectl autocompleteion rules.." && tput setaf 7
export KUBECONFIG=/etc/kubernetes/admin.conf
apt-get install -y bash-completion
source /usr/share/bash-completion/bash_completion
cat <<EOT >> /etc/modules-load.d/k8s.conf
source /usr/share/bash-completion/bash_completion
EOT
echo 'source <(kubectl completion bash)' >> /etc/bash.bashrc
echo 'alias k=kubectl' >> /etc/bash.bashrc
echo 'complete -F __start_kubectl k' >> /etc/bash.bashrc
tput setaf 2 && echo "Done. Next steps: 1. Install overlay driver on master (node) - here. 2. Add worker nodes" && tput setaf 7
#kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml