DEV Community

Mark
Mark

Posted on

Install and Set Up Kubernetes on Linux

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
Enter fullscreen mode Exit fullscreen mode

vim /etc/hosts

192.168.x.x k8-smaster
192.168.x.x k8-node1
192.168.x.x k8-node2
Enter fullscreen mode Exit fullscreen mode

Disable Selinux

Check

[root@dev-server ~]# getenforce
Disabled
[root@dev-server ~]# /usr/sbin/sestatus -v
SELinux status:                 disabled
Enter fullscreen mode Exit fullscreen mode

Temporarily Closed

##Set SELinux to permissive mode
##setenforce 1 sets SELinux to enforcing mode
setenforce 0
Enter fullscreen mode Exit fullscreen mode

Permanently Disable

vi /etc/selinux/config
Enter fullscreen mode Exit fullscreen mode

Change SELINUX=enforcing to SELINUX=disabled. The setting will take effect after a restart.

Swap Off

Check

free -m
Enter fullscreen mode Exit fullscreen mode

Temporarily Closed

swapoff -a
Enter fullscreen mode Exit fullscreen mode

Permanently Disable

sed -ri 's/.*swap.*/#&/' /etc/fstab
Enter fullscreen mode Exit fullscreen mode

Disable Firewall

systemctl status firewalld
systemctl stop firewalld
systemctl disable firewalld
chkconfig iptables off
sudo iptables -F
sudo iptables -X
sudo iptables -L
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Installing kubeadm, kubelet and kubectl

https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/

Image description

kubeadm config images pull --cri-socket unix:///var/run/cri-dockerd.sock
kubeadm version
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Next step, install canal and dashboard.

Top comments (1)

Collapse
 
der_gopher profile image
Alex Pliutau

Great write-up, we also have a bunch of articles on Kubernetes, check it out here - packagemain.tech