当前位置:网站首页>Kubernetes - bare metal cluster environment

Kubernetes - bare metal cluster environment

2022-06-22 05:16:00 Wu Shengzi night song

The master node needs

  • docker( It can be another container runtime )
  • kubectl( Cluster command line interaction tool )
  • kubeadm( Cluster initialization tool )

Work node needs

  • docker( It can also be another container runtime )
  • kubelet( management Pod And the container , Ensure their healthy and stable operation )
  • kube-proxy( Network proxy , Responsible for network related work )

Get ready 3 Servers

  • Master (10.0.20.9)

  • Node1 (10.0.8.8)

  • Node2 (10.0.12.12)

Set the corresponding host name for each node

hostnamectl set-hostname master
hostnamectl set-hostname node1
hostnamectl set-hostname node2

 Insert picture description here
 Insert picture description here
 Insert picture description here

All nodes are modified hosts

vim /etc/hosts

10.0.20.9 master
10.0.8.8 node1
10.0.12.12 node2

All nodes shut down SELinux

setenforce 0
sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux

All nodes ensure that the firewall is turned off

systemctl stop firewalld
systemctl disable firewalld

close swap

sudo swapoff -a ( If the machine restarts , This sentence needs to be executed again )
It can also be permanently disabled
sudo vim /etc/fstab
take swap Comment out that line

Add installation source

add to k8s Install 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=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

add to Docker Install source

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

Install the required components ( All nodes )

#  Don't pretend 1.24, Failed to initialize cluster 
yum install -y  docker-ce
yum install -y kubelet-1.23.0
yum install -y kubeadm-1.23.0
yum install -y kubectl-1.23.0

start-up kubelet、docker, And set boot up ( All nodes )

systemctl enable kubelet
systemctl start kubelet
systemctl enable docker
systemctl start docker

modify docker To configure ( All nodes )

# kubernetes The official recommendation docker Etc systemd As cgroupdriver, otherwise kubelet It won't start 
cat <<EOF > daemon.json { "exec-opts": ["native.cgroupdriver=systemd"], "registry-mirrors": ["https://ud6340vz.mirror.aliyuncs.com"] } EOF
mv daemon.json /etc/docker/


#  Restart and take effect 
systemctl daemon-reload
systemctl restart docker

use kuberadm Initialize cluster ( Primary node only )

#  Initialize the cluster console  Control plan
#  If you fail, you can use  kubeadm reset Reset 
kubeadm init --kubernetes-version=v1.23.0 --image-repository=registry.aliyuncs.com/google_containers --v=6


#  Remember to kubeadm join xxx Save up 
#  If you forget it, you need to get it again :kubeadm token create --print-join-command

#  Copy authorization file , In order to kubectl You can have access to the cluster 
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config


# Create... On other machines  ~/.kube/config  Documents can also pass kubectl Access to cluster 

 Insert picture description here

 Insert picture description here

Add the work node to the cluster ( Run only on the work node )

#  Returned when initializing the cluster 
kubeadm join 10.0.20.9:6443 --token 0dlyrh.wpzp6dvpx5fdxfzt --discovery-token-ca-cert-hash sha256:5b6f9a7d6ac30904c6b2018567930ff7ca3d652f804bbb100a72360003305d75

 Insert picture description here

Look at the node :kubectl get node
 Insert picture description here

Install network plug-ins , otherwise node yes NotReady state ( Master node operation )

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

 Insert picture description here

The node has Ready:
 Insert picture description here

原网站

版权声明
本文为[Wu Shengzi night song]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206220510266122.html