สวัสดีครับทุกท่าน ในวันนี้เราก็จะมาติดตั้งตัว 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
sudo swapoff -a
updates all the packages
sudo yum update -y
Installs the YUM utilities, device mapper, and LVM2
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
Adds the official Docker repository
sudo yum-config-manager –add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
Installs Docker Community Edition (CE)
sudo yum install -y \
containerd.io \
docker-ce \
docker-ce-cli
Creates a new directory at /etc/docker
sudo mkdir /etc/docker
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”
}
EOF
Creates a directory for Docker service overrides.
sudo mkdir -p /etc/systemd/system/docker.service.d
Reloads the systemd configuration
sudo systemctl daemon-reload
Restarts the Docker service
sudo systemctl restart docker
Enables the Docker service
sudo systemctl enable docker
Temporarily sets the SELinux policy to permissive mode
sudo setenforce 0
Permanently changes the SELinux policy to permissive mode
sudo sed -i ‘s/^SELINUX=enforcing$/SELINUX=permissive/’ /etc/selinux/config
Overwrites the existing Kubernetes repository configuration
cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://pkgs.k8s.io/core:/stable:/v1.29/rpm/
enabled=1
gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.29/rpm/repodata/repomd.xml.key
exclude=kubelet kubeadm kubectl cri-tools kubernetes-cni
EOF
Installs the Kubernetes components kubelet, kubeadm, and kubectl
sudo yum install -y kubelet kubeadm kubectl –disableexcludes=kubernetes
Enables the kubelet service
sudo systemctl enable –now kubelet
Removes the default containerd configuration file
sudo rm /etc/containerd/config.toml
Restarts the containerd service
sudo systemctl restart containerd
Adds a setting to the sysctl configuration
echo “net.bridge.bridge-nf-call-iptables = 1” | sudo tee -a /etc/sysctl.conf
Applies the new sysctl settings
sudo sysctl -p
Initializes a new Kubernetes cluster with a specified CIDR block for pod networking.
sudo kubeadm init –pod-network-cidr=192.168.0.0/16
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
Deploys the Calico network plugin, which provides networking and network policy
kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.27.3/manifests/tigera-operator.yaml
kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.27.3/manifests/custom-resources.yaml
Removes the taint from all nodes
kubectl taint nodes –all node-role.kubernetes.io/control-plane-
===สำหรับเครื่อง Worker Node ติดตั้งแค่ตาม Step 1 – 22 นะครับ===
#Join Worker Node to Master
Run Node 1 : kubeadm join xxx.xxx.x.xxx:6443 –token nraqf2.myj12wgp2as23sd \
–discovery-token-ca-cert-hash sha256:33581a7fdc47da4d549788e62349067c6e0ba66eec8bc35eb28b9ab421d5a76c –ignore-preflight-errors=all
Run Node 2 : kubeadm join xxx.xxx.x.xxx:6443 –token nraqf2.myj12wgp2as23sd \
–discovery-token-ca-cert-hash sha256:33581a7fdc47da4d549788e62349067c6e0ba66eec8bc35eb28b9ab421d5a76c –ignore-preflight-errors=all
จากนั้นลองไปที่เครื่อง Master Node
kubectl get pod –all-namespaces
สำหรับวันนี้มีเพียงเท่านี้ ขอบคุณครับ
Cr. Marco