-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-kubernetes-node-centos.sh
executable file
·94 lines (77 loc) · 2.94 KB
/
setup-kubernetes-node-centos.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
90
91
92
93
94
#!/bin/bash
set -x
set -e
# Make sure only root can run our script
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
# Check to make sure script is running on CentOS/Redhat
if [ ! -f /etc/redhat-release ]; then
echo "This script is for CentOS"
exit
fi
# Swap must be off
swapoff -a
sed -i.bak '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
# Configure FirewallD
wget -P /etc/firewalld/services https://raw.githubusercontent.com/wrightrocket/k8s-firewalld/master/k8s-worker.xml
systemctl enable firewalld
systemctl start firewalld
firewall-cmd --reload
firewall-cmd --add-service k8s-worker --permanent
firewall-cmd --reload
# Kubernetes Repo
cat << EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
# disable SELinux
setenforce 0
sed -i 's/enforcing/permissive/g' /etc/selinux/config
# Install Kubernetes
yum install -y kubelet kubeadm kubectl
systemctl enable kubelet
systemctl start kubelet
# Network forwarding
cat << EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
# Run on master node only!
#kubeadm init --pod-network-cidr=10.244.0.0/16
#mkdir -p $HOME/.kube
#cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
#chown $(id -u):$(id -g) $HOME/.kube/config
# Verify node is ready
#kubectl get nodes
#read -p "Press [Enter] to confirm"
# Verify kube-system pods are ready
#kubectl get pods --all-namespaces
#read -p "Press [Enter] to confirm"
# Install Flannel networking
#kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/bc79dd1505b0c8681ece4de4c0d86c5cd2643275/Documentation/kube-flannel.yml
# Node is ready
echo Join node to cluster with token.
echo "eg. kubeadm join --token <token> vm-k8s-01.doc.ic.ac.uk:6443"
echo on Kubernetes master use kubeadm token list to fetch token
echo If there is no current token create one with kubeadm token create --ttl 3600
read -p 'Token: ' token
# Ignoring CA Hashes verficaton for now #tofix
kubeadm join --token $token vm-k8s-01.doc.ic.ac.uk:6443 --discovery-token-unsafe-skip-ca-verification --ignore-preflight-errors=all
#Configure flannel
yum -y install flannel
# The etcd prefix value in the file /etc/sysconfig/flanneld is not correct, so the flanneld will fail to start as it is not able to retrieve the prefix given. The value of FLANNEL_ETCD_PREFIX must changed to the following:
sed -i 's|FLANNEL_ETCD_PREFIX="/atomic.io/network"|FLANNEL_ETCD_PREFIX="/coreos.com/network"|g' /etc/sysconfig/flanneld
# Enable and start flanneld
systemctl enable flanneld --now
# Configure kubectl for user
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config