-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkubernetes worker node.sh
64 lines (49 loc) · 2.01 KB
/
kubernetes worker node.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
#!/bin/bash
# Update system packages
sudo yum update -y
sudo yum install -y yum-utils
# Disable SELinux
sudo setenforce 0
sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
# Disable swap
sudo swapoff -a
sudo sed -i '/swap/d' /etc/fstab
# Add Docker Repo
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# Install Docker
sudo yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo systemctl enable docker
sudo systemctl start docker
# Add Kubernetes repository and install components
sudo tee /etc/yum.repos.d/kubernetes.repo <<EOF
[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
sudo yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
# Enable and start kubelet service
sudo systemctl enable kubelet --now kubelet
sudo systemctl start kubelet
# Remove containerd config and restart containerd
sudo rm /etc/containerd/config.toml
sudo systemctl restart containerd
# Enable IP forwarding
echo '1' | sudo tee /proc/sys/net/ipv4/ip_forward
# Load kernel modules
sudo modprobe bridge
sudo modprobe br_netfilter
# Initialize Kubernetes cluster
#sudo kubeadm init --pod-network-cidr=192.168.0.0/16
# Configure kubectl
# mkdir -p $HOME/.kube
# sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
# sudo chown $(id -u):$(id -g) $HOME/.kube/config
# Install network plugin (Calico used as an example)
#kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.26.0/manifests/tigera-operator.yaml
#kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.26.0/manifests/custom-resources.yaml
# Add export KUBECONFIG to bashrc
echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> $HOME/.bashrc