This article is about setting up kubernetes use kubeadm.
Prerequisites
Prepare two or more servers running Linux in the same network.
Set Hostname
sudo hostnamectl set-hostname k8-smaster
sudo hostnamectl set-hostname k8-node1
sudo hostnamectl set-hostname k8-node2
vim /etc/hosts
192.168.x.x k8-smaster
192.168.x.x k8-node1
192.168.x.x k8-node2
Disable Selinux
Check
[root@dev-server ~]# getenforce
Disabled
[root@dev-server ~]# /usr/sbin/sestatus -v
SELinux status: disabled
Temporarily Closed
##Set SELinux to permissive mode
##setenforce 1 sets SELinux to enforcing mode
setenforce 0
Permanently Disable
vi /etc/selinux/config
Change SELINUX=enforcing to SELINUX=disabled. The setting will take effect after a restart.
Swap Off
Check
free -m
Temporarily Closed
swapoff -a
Permanently Disable
sed -ri 's/.*swap.*/#&/' /etc/fstab
Disable Firewall
systemctl status firewalld
systemctl stop firewalld
systemctl disable firewalld
chkconfig iptables off
sudo iptables -F
sudo iptables -X
sudo iptables -L
Enable IPv4 packet forwarding
https://kubernetes.io/docs/setup/production-environment/container-runtimes/
# sysctl params required by setup, params persist across reboots
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.ipv4.ip_forward = 1
EOF
# Apply sysctl params without reboot
sudo sysctl --system
Install Docker
https://docs.docker.com/engine/install/centos/
Install CRI
wget https://github.com/Mirantis/cri-dockerd/releases/download/v0.3.14/cri-dockerd-0.3.14.amd64.tgz
tar xvf cri-dockerd-0.3.14.amd64.tgz
mv ./cri-dockerd/* /usr/local/bin/
wget https://raw.githubusercontent.com/Mirantis/cri-dockerd/master/packaging/systemd/cri-docker.service
wget https://raw.githubusercontent.com/Mirantis/cri-dockerd/master/packaging/systemd/cri-docker.socket
sudo mv cri-docker.socket cri-docker.service /etc/systemd/system/
sudo sed -i -e 's,/usr/bin/cri-dockerd,/usr/local/bin/cri-dockerd,' /etc/systemd/system/cri-docker.service
systemctl daemon-reload
systemctl enable cri-docker.service
systemctl enable --now cri-docker.socket
systemctl status cri-docker.socket
Installing kubeadm, kubelet and kubectl
https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/
kubeadm config images pull --cri-socket unix:///var/run/cri-dockerd.sock
kubeadm version
Init Master Node
kubeadm init \
--apiserver-advertise-address=192.168.116.133 \
--control-plane-endpoint=k8smaster \
--kubernetes-version=v1.30.2 \
--service-cidr=10.96.0.0/16 \
--pod-network-cidr=192.168.0.0/16 \
--cri-socket=unix:///var/run/cri-dockerd.sock
Join Node into Master
kubeadm join k8smaster:6443 --token cgdl45.0c8wq1z9pxez59jr \
--discovery-token-ca-cert-hash sha256:2fabc33e8c57c01f3214cf69dff97acc54ad6dd727f1255143bf310c4b40e2cb --cri-socket=unix:///var/run/cri-dockerd.sock
Next step, install canal and dashboard.
Top comments (1)
Great write-up, we also have a bunch of articles on Kubernetes, check it out here - packagemain.tech