First, basic environment preparation

Install/update docker

Blog.csdn.net/qq_39629343…

Method 1: Network installation
# 1. The list contains the docker software information field of the RPM - qa | grep docker # 2. Uninstall software yum remove docker - 1.13.1-53. Git774336d. El7. Centos. X86_64 - yum y remove Docker - the client - 1.13.1-53. Git774336d. El7. Centos. X86_64 - yum y remove docker - common - 1.13.1-53. Git774336d. El7. Centos. X86_64 -y # 3. Use curl to upgrade to the latest version of the curl - fsSL https://get.docker.com/ | sh # 4. Docker systemctl restart Docker # 5 Docker # 6 View Docker version information Docker Version # 7. View Docker system information, including the number of images and containers... Docker info # 8. Use the docker images command to check whether your previous image existsCopy the code
Method 2: Offline file installation

Install docker offline on Linux 19.03.5. Install Docker offline on Linux 19.03.5

Containerd. IO > = 1.2.2-3 error # yum install https://download.docker.com/linux/fedora/30/x86_64/stable/Packages/containerd.io-1.2.6-3.3.fc30.x86_64.rpm yum Localinstall containerd.io-1.2.6-3.3.fc30.x86_64. RPM # yum install https://download.docker.com/linux/fedora/30/x86_64/stable/Packages/docker-ce-cli-19.03.9-3.fc30.x86_64.rpm yum # yum install docker-ce-cli-19.03.9-3.fc30.x86_64 https://download.docker.com/linux/fedora/30/x86_64/stable/Packages/docker-ce-19.03.9-3.fc30.x86_64.rpm yum localinstall Docker - ce - 19.03.9-3. El7. X86_64. RPMCopy the code

If containerd. IO contains containerd-ce, docker-ce cli, and docker-ce in the same directory, run the following command to install it:

yum localinstall -y *.rpm
Copy the code

Disable the firewall and SELINUX

To prevent network problems caused by firewalls during the learning phase, skip this step in the production environment

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
systemctl disable firewalld
systemctl stop firewall
Copy the code

Switch off

Can be understood as virtual memory, k8S use as far as possible do not use the swap area, to prevent unexpected problems

/dev/mapper/centos-swap swap defaults 0 0Copy the code

Configure bridge/system routing parameters

Prevents Kubeadm from reporting routing warnings

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

Modifying the hosts file

Resolve host names locally

Cat <<"EOF">/etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4. Localdomain4 ::1 localhost Localhost. Localdomain localhost6 localhost6. Localdomain6 192.168.102.139 Master 192.168.102.140 node1 192.168.102.141 node2 EOFCopy the code
Hostnamectl set-hostname <your_hostname>Copy the code

Modify cgroupfs

www.cnblogs.com/ExMan/p/116…

Vi /etc/docker/daemon.json {"exec-opts":["native. Cgroupdriver =systemd"]} # reload systemctl daemon-reload systemctl restart docker systemctl status dockerCopy the code

Set the system time zone and synchronize the time server

yum install -y ntpdate
ntpdate time.windows.com
Copy the code

Two, K8S cluster installation

Several ways to install K8S

  • Several modes of k8S cluster deployment in China
  • K8s – Three ways and differences of cluster building, kubeadm, minikube, binary package

Deploy K8S using kubeadm

Centos7.7 Using Kubeadm to Rapidly Deploy a K8s Cluster (suitable for novices) Using Kubeadm to rapidly deploy a K8s cluster K8s Installation and Deployment Procedure Install the K8s offline

Kubectl, Kubelete, kubeadm installation
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[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
setenforce 0
Copy the code
Yum install -y kubeadm kubectl # yum install -y kubeadm kubectl # yum install -y kubeadm kubectl # kubelet && systemctl start kubeletCopy the code

Initialize (master node only) :

Kubeadm init \ --apiserver-advertise-address=192.168.102.137 \ --image-repository Registry.aliyuncs.com/google_containers \ - kubernetes - version v1.19.2 \ - service - cidr = 10.1.0.0/16 \ - pod - network - cidr = 10.244.0.0/16Copy the code

Execute as prompted (master node only) :

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

View Nodes and Pods:

kubectl get nodes
kubectl get pod -n kube-system
Copy the code
Installing the Flannel Network Component (master node only)

Docker. IO, gcr. IO, quay. IO Image acceleration

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

You are advised to pull the kube-flannel.yml file and its image to the local PC in advance

Adding a Node

K8s Delete node K8S Cluster node status Notready How can I add a role to a node in Kubernetes?

kubeadm token create --print-join-command
Copy the code
Application installation and access

K8s series installation K8S Dashboard note:

  1. Can be in advancedocker pull eipwork/kuboard:latest
  2. Modify theimagePullPolicyA value ofIfNotPresentNever
Configure kubectl command completion

Kubectl is used for k8S cluster interaction with a command line tool, the operation of K8S is basically inseparable from this tool, so the tool supports more commands. Fortunately, Kubectl supports completion of setup commands, so you can use Kubectl completion -h to view examples of setup on various platforms. The following uses Linux as an example to demonstrate how to configure command completion. After completing the following operations, you can use the TAP key to complete the command.

[root@master ~]# yum install bash-completion -y
[root@master ~]# source /usr/share/bash-completion/bash_completion
[root@master ~]# source <(kubectl completion bash)
[root@master ~]# kubectl completion bash > ~/.kube/completion.bash.inc
[root@master ~]# printf "  
# Kubectl shell completion  
source '$HOME/.kube/completion.bash.inc'  
" >> $HOME/.bash_profile
[root@master ~]# source $HOME/.bash_profile
Copy the code

Relevant learning materials and references

Cread.jd.com/read/startR… Github.com/kubeguide/K…