How to Install Kubernetes Cluster on CentOS 7


สวัสดีครับทุกท่าน ในวันนี้เราก็จะมาติดตั้งตัว Kubernetes Cluter บน CentOS 7 กันนะครับ

สำหรับการติดตั้งผมจะไม่ได้แนะนำการสร้าง Resouce สำหรับ CentOS นะครับ ผมจะคิดว่าทุกท่านมี Resouce แล้ว


#Step 1 : Change hostname to master1
hostnamectl set-hostname master1

#Step 2 : Disable firewalld service
systemctl status firewalld
## type yourself don’t copy & paste
systemctl stop firewalld
## type yourself don’t copy & paste
systemctl disable firewalld

#Step 3 : turns off the swap memory
sudo swapoff -a

#Step 4 :
updates all the packages 
sudo yum update -y

#Step 5 :
Installs the YUM utilities, device mapper, and LVM2
sudo yum install -y yum-utils device-mapper-persistent-data lvm2

#Step 6 :
Adds the official Docker repository 
sudo yum-config-manager –add-repo \

# Step 7 :
Installs Docker Community Edition (CE) 
sudo yum install -y \ \
docker-ce \

#Step 8 :
Creates a new directory at /etc/docker
sudo mkdir /etc/docker

#Step 9 :
Writes a custom configuration for the Docker daemon to a file named daemon.json.
cat <<EOF | sudo tee /etc/docker/daemon.json
“exec-opts”: [“native.cgroupdriver=systemd”],
“log-driver”: “json-file”,
“log-opts”: {
“max-size”: “100m”
“storage-driver”: “overlay2”

#Step 10 :
Creates a directory for Docker service overrides. 
sudo mkdir -p /etc/systemd/system/docker.service.d

#Step 11 :
Reloads the systemd configuration
sudo systemctl daemon-reload
#Step 12 : Restarts the Docker service 
sudo systemctl restart docker

#Step 13 :
Enables the Docker service 
sudo systemctl enable docker

#Step 14 :
Temporarily sets the SELinux policy to permissive mode
sudo setenforce 0
#Step 15 : Permanently changes the SELinux policy to permissive mode
sudo sed -i ‘s/^SELINUX=enforcing$/SELINUX=permissive/’ /etc/selinux/config

#Step 16 :
Overwrites the existing Kubernetes repository configuration 
cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
exclude=kubelet kubeadm kubectl cri-tools kubernetes-cni

#Step 17 :
Installs the Kubernetes components kubelet, kubeadm, and kubectl
sudo yum install -y kubelet kubeadm kubectl –disableexcludes=kubernetes

#Step 18 :
Enables the kubelet service 
sudo systemctl enable –now kubelet

#Step 19 :
Removes the default containerd configuration file
sudo rm /etc/containerd/config.toml
#Step 20 : Restarts the containerd service
sudo systemctl restart containerd

#Step 21 :
Adds a setting to the sysctl configuration 
echo “net.bridge.bridge-nf-call-iptables = 1” | sudo tee -a /etc/sysctl.conf
#Step 22 : Applies the new sysctl settings
sudo sysctl -p

#Step 23 :
Initializes a new Kubernetes cluster with a specified CIDR block for pod networking.
sudo kubeadm init –pod-network-cidr=

#Step 24 :
Creates a directory for the user’s Kubernetes configuration 
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

#Step 25 :
Deploys the Calico network plugin, which provides networking and network policy
kubectl create -f
kubectl create -f

#Step 26 : Removes the taint from all nodes 
kubectl taint nodes –all

===สำหรับเครื่อง Worker Node ติดตั้งแค่ตาม Step 1 – 22 นะครับ===
#Join Worker Node to Master

Run Node 1 : kubeadm join –token nraqf2.myj12wgp2as23sd \
–discovery-token-ca-cert-hash sha256:33581a7fdc47da4d549788e62349067c6e0ba66eec8bc35eb28b9ab421d5a76c –ignore-preflight-errors=all
Run Node 2  : kubeadm join –token nraqf2.myj12wgp2as23sd \
–discovery-token-ca-cert-hash sha256:33581a7fdc47da4d549788e62349067c6e0ba66eec8bc35eb28b9ab421d5a76c –ignore-preflight-errors=all

จากนั้นลองไปที่เครื่อง Master Node 
kubectl get pod –all-namespaces



สำหรับวันนี้มีเพียงเท่านี้ ขอบคุณครับ

Cr. Marco