当前位置:网站首页>Kubedm builds kubernetes cluster
Kubedm builds kubernetes cluster
2022-07-28 21:27:00 【SQ Xia Yan】
List of articles
One . Cluster introduction
1.1 Cluster building method
The current production deployment Kubernetes There are two main ways to cluster :
- Kubeadm
Kubeadm It's a K8s Deployment tools , Provide kubeadm init and kubeadm join, For rapid deployment Kubernetes colony . - Binary package
from github Download the distribution's binary package , Manually deploy each component , form Kubernetes colony .
Kubeadm Lower deployment threshold , But it's a lot of detail , It's hard to troubleshoot problems . If you want to be more controllable , Binary package deployment is recommended Kubernetes colony , Although manual deployment is troublesome , You can learn a lot about how it works , It's also good for later maintenance .
1.2 Cluster architecture
At present, one master and one slave are generally used to build clusters 、 Multi master and multi slave cluster architecture ( High availability )
Two . Cluster deployment
This article uses one master and two slaves , A total of three servers are built k8s colony
2.1 Environment configuration
The following operations are required for all three servers
- close swap
# Temporarily Closed swapoff -a
# Permanent ban , Need to restart
sed -i 's/.*swap.*/#&/' /etc/fstab
# see ,swap It has to be for 0
free -g

- Add host mapping
echo "192.168.48.14 k8s" >>/etc/hosts
echo "192.168.48.13 k8s-node1" >>/etc/hosts
echo "192.168.48.11 k8s-node2" >>/etc/hosts

- To be bridged IPv4 Flow to iptables Chain
cat > /etc/sysctl.d/k8s.conf << EOF net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 net.ipv4.ip_forward=1 EOF
# Refresh
sysctl --system
- docker install
# Turn off the firewall and selinux
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config
# Install dependency packages
yum install -y yum-utils device-mapper-persistent-data lvm2
# Configure alisource
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# install docker
yum install -y docker-ce
systemctl start docker
systemctl enable docker
# modify docker Resource management
vim /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"]
}
systemctl daemon-reload
systemctl restart docker
- To configure K8s 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
# Install the software
yum install -y kubelet-1.21.3 kubeadm-1.21.3 kubectl-1.21.3
systemctl enable kubelet
systemctl start kubelet
2.2 master Node making
stay master Master server operation , Perform cluster initialization , Pay attention to changing your own ip Information
kubeadm init --apiserver-advertise-address=192.168.48.14 --image-repository registry.cn-hangzhou.aliyuncs.com/google_containers --kubernetes-version v1.21.3 --service-cidr=10.125.0.0/16 --pod-network-cidr=10.150.0.0/16

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
ps: In the command to join the cluster token== Valid for 24 Hours ==, If overdue , Need to reapply token
# Generate token
kubeadm token create
# see token
kubeadm token list | awk -F" " '{print $1}'
# obtain CA Public key hash value
openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^ .* //'

2.3 node Nodes join the cluster
kubeadm join 192.168.48.14:6443 --token brc1q1.tnuas794b21c6l7a \
--discovery-token-ca-cert-hash sha256:c3b8b3b770b60af4bc884b4034cc9ab922ae49700f41628b83a25b651e72111d

2.4 Add network plug-ins
###################### Network add ############################
# add to
kubectl apply -f \
https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
# Delete
kubectl delete -f \
https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
######################weget download ##########################
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
# Changing configuration files
vim kube-flannel.yml
# take IP Change to master When making nodes IP Address
84 "Network": "10.150.0.0/16"
# Add the plug-in
kubectl apply -f + kube-flannel.yml The path of

to node Add tags
kubectl label node k8s-node1 node-role.kubernetes.io/node=node
kubectl label node k8s-node2 node-role.kubernetes.io/node=node
# Get node information
kubectl get nodes

master Check
# Inquire about master If there is something wrong
kubectl get cs
# if unhealthy
vim /etc/kubernetes/manifests/kube-scheduler.yaml
vim /etc/kubernetes/manifests/kube-controller-manager.yaml
- --port=0 # Comment out , Each file has a line
kube-controller-manager.yaml File modification : Comment out 27 That's ok 
kube-scheduler.yaml Configuration modification : Comment out 19 That's ok ,- --port=0
2.5 Service deployment
testing K8s Whether the cluster is normal , Then run the service deployment
# Query all pod Is it working
kubectl get pods -A
# Inquire about master If there is something wrong
kubectl get cs
# Inquire about node Is the node ready
kubectl get nodes

# Deployment Services
kubectl create deployment nginx --image=nginx:1.14
# Exposed port
kubectl expose deployment nginx --port=80 --type=NodePort
kubectl get pods
kubectl get svc
# Delete pod And svc
kubectl delete deploy/nginx
kubectl delete svc/nginx

Access test :
2.6 Error message
If the following error occurs :
Failed to run kubelet" err="failed to run Kubelet: misconfiguration: kubelet cgroup driver: \"cgroupfs\" is diffelet: misconfiguration: kubelet cgroup driver: \"cgroupfs\" is different from docker cgroup driver: \"systemd\""
Error reporting fault :docker And k8s Different resource managers kubelet cgroup driver: “cgroupfs” is different from docker cgroup driver: “systemd”"
resolvent : modify docker And k8s The resource manager of is systemd
Inquire about docker Of cgroup
#docker modify
vim /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"]
}
# Restart the service
systemctl daemon-reload
systemctl restart docker
#k8s Modification method
vim /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
# or vim /usr/lib/systemd/system/kubelet.service.d/10-kubeadm.conf
--cgroup-driver=systemd
# Restart the service
systemctl daemon-reload
systemctl restart kubelet

边栏推荐
- System integration under microservice architecture
- MySQL
- 1162. Map analysis - non recursive method
- Explain C language 12 in detail (C language series)
- 广和通&高通物联网技术开放日成功举办
- 证券企业基于容器化 PaaS 平台的 DevOps 规划建设 29 个典型问题总结
- What is low code? Which platforms are suitable for business personnel? Is it reliable to develop the system?
- The ref value ‘xxx‘ will likely have changed by the time this effect function runs. If this ref......
- ctfshow 网络迷踪做题记录(1)
- 到底为什么不建议使用SELECT * ?
猜你喜欢
![[input ID number] is replaced by an asterisk, and input is cut into multiple small squares (similar)](/img/f0/7e3ea94e02a42b6055c40b58d1e39c.png)
[input ID number] is replaced by an asterisk, and input is cut into multiple small squares (similar)

Eureka registers with each other, only showing each other or only showing problems in one

Attribute based encryption simulation and code implementation (cp-abe) paper: ciphertext policy attribute based encryption

ctfshow 网络迷踪做题记录(1)

Nacos principle

What is ci/cd| Achieve faster and better software delivery

实现瀑布流效果

Guanghetong & Qualcomm Internet of things technology open day successfully held

上市1个月接连发生两起安全事故,理想L9还理想吗?

ctfshow 做题 web模块 web11~web14
随机推荐
Niuke turns on the camera and the picture disappears a few seconds later | the picture flashes when the camera is turned on
How to build a foreign environment for the self-supporting number of express evaluation? How much does it cost?
Quii Cordova plugin telerik imagepicker plug-in multi image upload out of sequence
什么是 CI/CD? | 实现更快更好的软件交付
【英雄哥七月集训】第 28天:动态规划
System integration under microservice architecture
ctfshow 网络迷踪做题记录(2)
Zcmu--5066: dark corridor
Moco V3: visual self supervision ushers in transformer
BUUCTF做题Upload-Labs记录pass-11~pass-20
详细讲解C语言12(C语言系列)
SSM-使用@Async和创建ThreadPoolTaskExecutor线程池
Maxwell 一款简单易上手的实时抓取Mysql数据的软件
Deit: attention can also be distilled
There have been two safety accidents in a month after listing. Is L9 ideal?
Uniapp progress bar customization
Color finder actual combat (QT including source code)
Introduction to blue team: efficiency tools
Paging function (board)
Analysis of critical path