Kubernetes Installation of the Kubernetes Family "Kubeadm Way Installation"

Kubeadm Way Installation

Posted by chyuan on 2022-11-11
Estimated Reading Time 6 Minutes
Words 1k In Total

General & Background

It’s been some time since studying Kubernetes and using Kubernetes for actual projects. Kubernetes series can be regarded as my learning record, first, briefly sort out some learning notes to share with you, revealing what is the very hot, popular Kubernetes ~, the emergence of new technology must have its reason, but don’t look at the flowers in the fog, feel particularly mysterious that’s it, this note starts with installation.

1.Pre-installation preparation (every server has to do this)

1.1 To close the swap partition:

1
$  sudo swapoff -a

1.2 Open the network bridge:

1
$ sudo modprobe br_netfilter

1.3 Adjust firewall settings:

1
2
3
4
5
$ cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf net.bridge.bridge-nf-call-ip6tables = 1

net.bridge.bridge-nf-call-iptables = 1

EOF
1
$ sudo sysctl --system

1.4 Get the k8s tool installation public key:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$ cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo

[kubernetes]

name=Kubernetes

baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-\$basearch

enabled=1

gpgcheck=1

repo_gpgcheck=1

gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg

exclude=kubelet kubeadm kubectl

EOF

1.5 Adjust permissions:

1
$ sudo setenforce 0
1
$ sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config

1.6 Set docker proxy: (if there is an HTTP proxy that can go to sea, please refer to the following configuration, if not, please skip)

1
$ sudo mkdir -p /etc/systemd/system/docker.service.d
1
$ touch /etc/systemd/system/docker.service.d/http-proxy.conf

Writing like this:

1
2
3
4
[Service]
Environment='HTTP_PROXY=http://10.25.192.8:3378/'
Environment='HTTPS_PROXY=http://10.25.192.8:3378/'
Environment='NO_PROXY=localhost,127.0.0.1'

To make the configuration take effect:

1
$ sudo systemctl daemon-reload
1
$ sudo systemctl restart docker

1.7 Download the necessary image packages and work packages for Kubernetes (if 1.6 is set, you can skip it, and you can use the following ways to go to the sea if there is no HTTP proxy available)

I originally planned to upload it myself, but I found that another big guy has already uploaded related images and tools on CSDN: Kubernetes 1.19.4 version images and tools
How to use the image:
Download and unzip and upload directly to the server Use “docker load -i xxx.tar” to use, don’t forget that the master node and worker node must be imported, kubeadm, kubectl and other installation packages installation methods please check yourself, no additional instructions are made here

1.8 Check the Kubernetes image

1
2
3
4
5
6
7
8
9
$ docker images 
REPOSITORY TAG IMAGE ID CREATED SIZE
k8s.gcr.io/kube-proxy v1.19.4 635b36f4d89f 6 months ago 118MB
k8s.gcr.io/kube-controller-manager v1.19.4 4830ab618586 6 months ago 111MB
k8s.gcr.io/kube-apiserver v1.19.4 b15c6247777d 6 months ago 119MB
k8s.gcr.io/kube-scheduler v1.19.4 14cd22f7abe7 6 months ago 45.7MB
k8s.gcr.io/etcd 3.4.13-0 0369cf4303ff 9 months ago 253MB
k8s.gcr.io/coredns 1.7.0 bfe3a36ebd25 11 months ago 45.2MB
k8s.gcr.io/pause 3.2 80d28bedfe5d 15 months ago 683kB

2.Install K8S

2.1 Install tools such as kubeadm (if you download offline packages, you can skip this command)

1
$ sudo yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes

2.2 On the master node, execute:

1
$ sudo kubeadm init --pod-network-cidr=10.244.0.0/16

Note: –pod-network-cidr=10.244.0.0/16 do not change the network segment randomly, otherwise it will have an impact on the next steps to install the network plug-in flannel, flannel defaults to this network segment, if there is a modification here, then the installation of flannel also needs to have corresponding adjustments, the specific adjustment method please search on flannel’s GitHub issue. Don’t ask me why I know ~~ I don’t know how I know.
After the installation is complete, it will print something similar to the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Your Kubernetes control-plane has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

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

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 172.17.100.191:6443 --token rk5************ \
--discovery-token-ca-cert-hash sha256:9a478***************************************************************************

2.3 On the worker node, execute:

1
2
$ kubeadm join 172.17.100.191:6443 --token rk5************ \
--discovery-token-ca-cert-hash sha256:9a478***************************************************************************

2.4 Install the network plugin (the network plugin is required, of course, other types can be selected, here flannel is an example)

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

3.Check the cluster status

1
2
3
4
5
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
master Ready 65111to65139,master 187d v1.19.4
node1 Ready 65141to65169,node 187d v1.19.4
node2 Ready 65171to65199,node 187d v1.19.4

If it is displayed as ready, the cluster status is normal, and the Kubernetes cluster installation is complete

4.Conclusion

  • When you see new technologies, don’t be afraid to go deeper, the emergence of new technologies must be because of the emergence of new needs, new needs appear, but the original solution to the corresponding problem is not enough, then it will promote the emergence and development of new technical theories.
  • Don’t learn new technology for the sake of learning new technology, because it is not easy to understand without specific use of new technology, starting from the problem to the solution and technology.
  • Don’t understand what new technology does, learn not to understand it, first learn to use it, and then complement each other with bold guesses, carefully verify.
  • The last sentence, it’s over, don’t instigate.

If you like this blog or find it useful for you, you are welcome to comment on it. You are also welcome to share this blog, so that more people can participate in it. If the images used in the blog infringe your copyright, please contact the author to delete them. Thank you !