Detailed introduction to deploying k8s cluster on centos7 system

Detailed introduction to deploying k8s cluster on centos7 system

1 Version and planning

1.1 Version information:

name Version Number
Kernel 3.10.0-1160.el7.x86_64
operating system CentOS Linux release 7.9.2009 (Core)
docker 20.10.11
kubeadm 1.23.0
kubelet 1.23.0
kubectl 1.23.0

1.2 Cluster Planning

IP hostname
192.168.0.114 k8s-master
192.168.0.115 k8s-node01
192.168.0.116 k8s-node02

2. Deployment

illustrate:

Step 1 to step 8, all nodes need to operate the master node: Step 9, 10 node node: Step 11

1. Turn off the firewall

To shut down: systemctl stop firewalld

Permanently disable: systemctl disable firewalld

2. Turn off selinux

To turn off: setenforce 0

3. Turn off swap

Temporary shutdown: swapoff -a

Permanently disable: sed -ri 's/.*swap.*/#&/' /etc/fstab , use this command to comment out the code containing swap line

Verify: free -m

4. Add the correspondence between host name and IP

Add the mapping relationship in /etc/hosts according to the planning content in 1.2

192.168.0.114 k8s-master
192.168.0.115 k8s-node01
192.168.0.116 k8s-node02

5. Pass the bridged IPV4 traffic to the iptables chain

Add the configuration using the following command:

cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

Run sysctl --system command to make the configuration take effect:

6. Install docker installation:

wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
yum install docker-ce

Set up automatic startup

systemctl start docker
systemctl enable docker

Check the version: docker version possible pitfalls (skip here for now, come back and modify them later):

Question: Use the command docker info|grep cgroup to check if Cgroup Driver used by docker is cgroupfs . It may conflict with kubelet and needs to be changed to consistent systemd

Solution 1: vi /etc/docker/daemon.json , add the following code to the file, and restart Docker

{
	"exec-opts": ["native.cgroupdriver=systemd"]
}

Solution 2: You can also modify ExecStart in the docker startup service and add the parameter "--exec-opt native.cgroupdriver=systemd"

#docker.service
vi /usr/lib/systemd/system/docker.service
# Add ExecStart=/usr/bin/dockerd --exec-opt native.cgroupdriver=systemd

7. Add Alibaba Cloud yum software source

cat > /etc/yum.repos.d/kubernetes.repo << EOF
[Kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

Potential pitfalls (skip here for now, come back later if you encounter them)

Problem: During the installation process, it may prompt that xxx.rpm 公鑰尚未安裝

Solution 1: After importing the public key, reinstall it again

wget https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
wget https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
rpm --import yum-key.gpg
rpm --import rpm-package-key.gpg

Solution 2: Configure gpgchekc to 0 in the kubernetes.repo file and do not check it.

8. Install kubeadm, kubelet, and kubectl

Installation: yum install -y kubelet-1.23.0 kubectl-1.23.0 kubeadm-1.23.0

Or install the latest version: yum install -y kubelet kubectl kubeadm

Set to start automatically: systemctl enable kubelet , here you only need to set it to start at boot. Because the configuration is not yet complete, there is no need to start it, and the startup will fail

9. Initialize the master node

Initialization Command

kubeadm init \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.23.0 \
--service-cidr=10.1.0.0/16 \
--pod-network-cidr=10.244.0.0/16

Parameter Description

--image-repository string Choose a container registry to pull control plane images from (default "k8s.gcr.io") Use Alibaba Cloud's registry here, otherwise it will be slow or even fail.

If the installation fails, you need to clean up the environment using the kubeadm reset command and then reinstall.

Pitfalls encountered:

Problem: The HTTP call equal to 'curl -sSL http://localhost:10248/healthz' failed with error: Get "http://localhost:10248/healthz": dial tcp [::1]:10248: connect: connection refused. Solution: See step 6 for details.

Report an error

Initialization is successful If the following result appears, it means that the initialization is successful

Initialization successful

According to the prompt, execute the following command

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

# The first command: indicates the creation of a hidden folder .kube
# The second command: means copying the file admin.conf to this folder # The third command: means setting the user and user group to which the file belongs

After executing the above commands, you can use the kubectl command. The connection to the server localhost:8080 was refused - did you specify the right host or port?

View Node

10. Install pod network plugin (CNI)

GitHub address: https://github.com/flannel-io/flannel, you can also download the file directly

flannel

Install the plugin:

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

Pitfalls encountered

Problem: The connection to the server raw.githubusercontent.com The connection to the server raw.githubusercontent.com was refused - did you specify the right host or port? Solution: Add raw.githubusercontent.com mapping in /etc/hosts . The IP address can be viewed at https://www.ipaddress.com

hosts

/etc/hosts

Check whether the deployment is successful: kubectl get pods -n kube-system

insert image description here

Check the node again and the status changes to ready

insert image description here

11. Node joins the cluster

To add a new node to the cluster, just copy kubeadm join command after successfully executing kubeadm init on the master node to the node to be added.

kubeadm join 192.168.0.114:6443 --token whxbm2.x70y9k1feop2604b \
  --discovery-token-ca-cert-hash sha256:d4306836b7ef32fd802e559cf717bbbe3af6dd75d3cb2fa4d3db7a16cc25a657

After successfully joining, use the command kubectl get nodes on the master node to find that the node has been added to the cluster and the status is ready (wait a moment here)

This is the end of this article about the detailed introduction of centos7 system deployment of k8s cluster. For more relevant centos7 deployment of k8s cluster content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Detailed steps to install and configure k8s cluster in centos 7

<<:  Summary of the use of Datetime and Timestamp in MySQL

>>:  17 excellent web designs carefully crafted by startups

Recommend

MySQL count detailed explanation and function example code

Detailed explanation of mysql count The count fun...

Vue implements carousel animation

This article example shares the specific code of ...

Example of using CSS3 to customize the style of input multiple-select box

Principle: First hide the input element, then use...

How to implement multiple parameters in el-dropdown in ElementUI

Recently, due to the increase in buttons in the b...

You may need a large-screen digital scrolling effect like this

The large-screen digital scrolling effect comes f...

JavaScript manual implementation of instanceof method

1. Usage of instanceof instanceof operator is use...

idea uses docker plug-in to achieve one-click automated deployment

Table of contents environment: 1. Docker enables ...

WeChat applet implements jigsaw puzzle game

This article shares the specific code for impleme...

Detailed tutorial on deploying Springboot or Nginx using Kubernetes

1 Introduction After "Maven deploys Springbo...

Circular progress bar implemented with CSS

Achieve results Implementation Code html <div ...

Understanding the Lazy Loading Attribute Pattern in JavaScript

Traditionally, developers create properties in Ja...

Docker configuration Alibaba Cloud Container Service operation

Configuring Alibaba Cloud Docker Container Servic...