-
Notifications
You must be signed in to change notification settings - Fork 45
/
kubernetes-master.sh
89 lines (67 loc) · 2.71 KB
/
kubernetes-master.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
#!/bin/bash
#UBUNTU_VERSION=18.04
#K8S_VERSION=1.11.3-00
#node_type=master
#Update all installed packages.
apt-get update -y
apt-get upgrade -y
#if you get an error similar to
#'[ERROR Swap]: running with swap on is not supported. Please disable swap', disable swap:
sudo swapoff -a
# install some utils
sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
#Install Docker
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
#if [ $UBUNTU_VERSION == "16.04" ]; then
# sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable"
#elif [ $UBUNTU_VERSION == "18.04" ]; then
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
#else
#default tested version
# sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable"
#fi
sudo apt-get update
sudo apt-get install -y docker.io
#Install NFS client
sudo apt-get install -y nfs-common
#Enable docker service
sudo systemctl enable docker.service
######### Copy Line 40-42 and run as one command ###########
#Kubernetes installation begins
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF
######### Copy Line 44-46 and run as one command ###########
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sudo sysctl --system
#Update the apt source list
sudo apt-get update && sudo apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
######### Copy Line 54-56 and run as one command ###########
cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
#Install K8s components
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
#Initialize the k8s cluster
sudo kubeadm init --pod-network-cidr=10.244.0.0/16
sleep 60
#Create .kube file if it does not exists
mkdir -p $HOME/.kube
#Move Kubernetes config file if it exists
#if [ -f $HOME/.kube/config ]; then
# mv $HOME/.kube/config $HOME/.kube/config.back
#fi
sudo cp -f /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
#if you are using a single node which acts as both a master and a worker
#untaint the node so that pods will get scheduled:
#kubectl taint nodes --all node-role.kubernetes.io/master-
#Install Flannel network
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.10.0/Documentation/kube-flannel.yml
echo "Done."