One, foreword

There are a few concepts to understand before installation

  • Node: a node, usually a machine

  • Pod: the smallest unit of K8S. K8s does not operate applications directly, but pods directly

Two, installation steps

1. Two VMS (with IP addresses configured based on the network environment) (Master /node)

192.168.100.215

k8s-master

192.168.100.216

k8s-node1

2. Disable the firewall (Master /node)

systemctl stop firewalld 
systemctl disable firewalld 
Copy the code

3, Disable selinux(master/node)

Setenforce 0 # temporarily disable sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config # Permanently disable sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/configCopy the code

4. Close swap(master/node)

Swapoff -a # Temporary shutdown; Sed -ri 's/.*swap.*/#&/' /etc/fstab #Copy the code

5. Add the mapping between host name and IP address (master/node)

$vim /etc/hosts # add the following contents: 192.168.100.215k8s-master 192.168.100.216k8s-node1 # Save and exitCopy the code

Change the host name (master/node)

#k8s-master [root@localhost ~] hostname localhost. Localdomain [root@localhost ~] hostname k8s-master ## [root@localhost ~] hostnamectl set-hostname k8s-master ## Permanent after restart #k8s-node1 [root@localhost ~] hostname Localhost. Localdomain [root@localhost ~] hostname k8s-node1 ## temporary effect [root@localhost ~] hostnamectl set-hostname k8s-node1 The value takes effect permanently after the restartCopy the code

7. Bridge Settings (Master /node)

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

p.s.

  • The above steps had better follow the implementation, so as not to report a lot of mistakes

Docker (master/node) if you have already installed Dokcer, you do not need to install it again

# $yum -y install wget add docker yum source $wget HTTP: / / https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -o /etc/yom.repos. D /docker-ce. Repo # install $yum -y install docker-ce # install $systemctl enable docker # install docker $ systemctl start dockerCopy the code

9, Add Aliyun YUM software source for Kubernetes (master/node)

cat > /etc/yum.repos.d/kubernetes.repo << EOF
[k8s]
name=k8s
enabled=1
gpgcheck=0 
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
EOF
Copy the code

Install kubeadm, kubelet and kubectl(master/node)

$yum install -y kubelet-1.18.0 kubectl-1.18.0 kubeadm-1.18.0 kubeadm-1.18.0 $yum install -y kubelet-1.18.0 kubectl-1.18.0 kubeadm-1.18.0 $systemctl enable kubelet cannot be started yet because the configuration is not available at this timeCopy the code

11, deploy Kubernetes (master),node does not need kubeadm init

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

The following information is displayed after the success:

Kubeadm join 192.168.100.215:6443 --token 5l6xl0.qwifh1s0hrxdss3f \ --discovery-token-ca-cert-hash sha256:cfd498dd8bb0e0d88cc45a795941906911dabc65f9251ae5479e5fb6ac85a472Copy the code

P.S. here is through kubeadm init, so after execution, the corresponding docker image will be downloaded, usually found in the console stuck for a long time, then is downloading the image, you can check docker images to see if there is a new image added.

12, use kubectl tool, kubeadm installed, the console will also be prompted to execute the following command, follow the execution

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

Test the kubectl command

[root@k8s-master ~]# kubectl get nodes
NAME         STATUS   ROLES    AGE   VERSION
k8s-master   NotReady    master   23m   v1.18.0
Copy the code

“NotReady” is the status of an application that is still being started. We will check later if it becomes “NotReady”

Install Pod network plug-in flannel(Master /node)

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

Error: The connection to The server raw.githubusercontent.com was refused – did you specify The right host or port? : Solution:

# sudo vim/etc/hosts in the/etc/hosts increased following the 199.232.28.133 raw.githubusercontent.comCopy the code

Re-execute the above command and the installation will be successful!

14. Add node to master(node)

Kubeadm join 192.168.100.215:6443 --token 5l6xl0.qwifh1s0hrxdss3f \ --discovery-token-ca-cert-hash sha256:cfd498dd8bb0e0d88cc45a795941906911dabc65f9251ae5479e5fb6ac85a472Copy the code

You can view it on the master node

$ kubectl get nodes
NAME         STATUS     ROLES    AGE   VERSION
k8s-master   Ready   master      22m   v1.18.0
k8s-node1    Ready      <none>   18m   v1.18.0 
Copy the code

Pay attention to

  • Pay attention to the version of the program you are installing

  • K8s components also exist in the form of docker containers, so many Dokcer images will be downloaded

  • General installation will not be in victory, there will be quite a few problems, with tailf /var/log/messages tracking under the log

  • It is better to synchronize the system time of several machines. The token in node communication is also related to time

Iii. Relevant notes

  • K8S kubeadm init kubeadm join

    Kubeadm token list kubeadm token list kubeadm token list kubeadm token list kubeadm token list kubeadm token list kubeadm token list

  • If kubeadm join fails on node, what can I do if I want to join again?

    Kubeadm -y reset kubeadm join xx…..

  • Restart kubelet

    systemctl daemon-reload systemctl restart kubelet

  • The query

    Kubectl get Nodes kubectl get Pods Without equivalent -n dafault kubectl get Pods -n kube-system

Reference article:

The local VIRTUAL machine centos7 environment to build K8S cluster – Practice

www.jianshu.com! [] icon (https://p3-juejin….