当前位置: 首页 > news >正文

银河麒麟v10 x86架构二进制方式kubeadm+docker+cri-docker搭建k8s集群(证书有效期100年) —— 筑梦之路

环境说明

master:192.168.100.100

node: 192.168.100.101

kubeadm 1.31.2 (自编译二进制文件,证书有效期100年)

银河麒麟v10 sp2  x86架构

内核版本:5.4.x  编译安装 cgroup v2启用

docker版本:27.x  二进制安装,cgroup v2支持

部署准备

# 关闭防火墙
systemctl disable firewalld --now# 关闭selinux
setenforce 0
sed -i 's/enforcing/disabled/' /etc/selinux/config#关闭swap
swapoff -a 
sed -ri 's/.*swap.*/#&/' /etc/fstab (永久关闭)# 主机名与IP对应关系
vim /etc/hosts
192.168.100.100 k8s-master
192.168.100.101 k8s-node# 添加内核优化参数
cat << EOF > /etc/sysctl.d/99-kubernetes-cri.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
user.max_user_namespaces=28633
EOF# 使其生效
sysctl -p /etc/sysctl.d/99-kubernetes-cri.conf# 配置ipvs转发
yum install -y ipset ipvsadm
cat > /etc/sysconfig/modules/ipvs.modules <<EOF
#!/bin/bash
modprobe -- ip_vs
modprobe -- ip_vs_rr
modprobe -- ip_vs_wrr
modprobe -- ip_vs_sh
modprobe -- nf_conntrack_ipv4
EOFchmod 755 /etc/sysconfig/modules/ipvs.modules && bash /etc/sysconfig/modules/ipvs.modules && lsmod | grep -e ip_vs -e nf_conntrack_ipv4
# 配置时间同步dnf install chronyd -ycat > /etc/chrony.conf <<EOF
server ntp.aliyun.com iburst
stratumweight 0
driftfile /var/lib/chrony/drift
rtcsync
makestep 10 3
bindcmdaddress 127.0.0.1
bindcmdaddress ::1
keyfile /etc/chrony.keys
commandkey 1
generatecommandkey
logchange 0.5
logdir /var/log/chrony
EOFsystemctl enable chronyd --now

二进制安装docker+cri-docker+cni插件

银河麒麟v10 二进制安装cri-docker+cni插件—— 筑梦之路-CSDN博客

安装kubeadm、kubelet、kubectl

将编译的二进制文件拷贝到/usr/bin/目录下,并授可执行权限

# 安装常用工具和依赖包
yum -y install  wget psmisc vim net-tools nfs-utils telnet yum-utils device-mapper-persistent-data lvm2 git tar curl ipvsadmyum install ipvsadm ipset sysstat conntrack libseccomp -yyum install socat libnetfilter_queue libnetfilter_cttimeout conntrack-tools libnetfilter_cthelper# 生成service文件
cat > /usr/lib/systemd/system/kubelet.service << EOF
[Unit]
Description=kubelet: The Kubernetes Node Agent
Documentation=https://kubernetes.io/docs/home/
Wants=network-online.target
After=network-online.target[Service]
ExecStart=/usr/bin/kubelet
Restart=always
StartLimitInterval=0
RestartSec=10[Install]
WantedBy=multi-user.target
EOFsystemctl daemon-reloadsystemctl enable kubelet
# 拉取所需镜像kubeadm config images pull --cri-socket unix:///var/run/cri-dockerd.sock --image-repository registry.aliyuncs.com/google_containers# 初始化kubeadm init --kubernetes-version=v1.31.2 \
--apiserver-advertise-address=192.168.100.100 \
--pod-network-cidr=10.244.0.0/16 \
--service-cidr=10.96.0.0/12 \
--token-ttl=0 \
--cri-socket unix:///var/run/cri-dockerd.sock \
--image-repository registry.aliyuncs.com/google_containers
接下来在worker节点上执行相关的操作,worker节点与master节点的操作步骤的唯一区别是:master节点执行kubeadm init操作,woker节点执行kubeadm join操作,因此上面的步骤除了kubeadm init步骤之外,其他所有的步骤woker节点同样也需要执行。执行kubeadm init 成功之后输出的 最后一行kubeadm join 命令kubeadm config images pull --cri-socket unix:///var/run/cri-dockerd.sock --image-repository registry.aliyuncs.com/google_containerskubeadm join 192.168.100.100:6443 --token o4zf8w.xxxx --discovery-token-ca-cert-hash sha256:376e215a51620ac6ccc --cri-socket unix:///var/run/cri-dockerd.sock
# 部署flannel插件cat > flannel.yaml << EOF
#---
#kind: Namespace
#apiVersion: v1
#metadata:
#  name: kube-flannel
#  labels:
#    k8s-app: flannel
#    pod-security.kubernetes.io/enforce: privileged
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:labels:k8s-app: flannelname: flannel
rules:
- apiGroups:- ""resources:- podsverbs:- get
- apiGroups:- ""resources:- nodesverbs:- get- list- watch
- apiGroups:- ""resources:- nodes/statusverbs:- patch
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:labels:k8s-app: flannelname: flannel
roleRef:apiGroup: rbac.authorization.k8s.iokind: ClusterRolename: flannel
subjects:
- kind: ServiceAccountname: flannelnamespace: kube-system
---
apiVersion: v1
kind: ServiceAccount
metadata:labels:k8s-app: flannelname: flannelnamespace: kube-system
---
kind: ConfigMap
apiVersion: v1
metadata:name: kube-flannel-cfgnamespace: kube-systemlabels:tier: nodek8s-app: flannelapp: flannel
data:cni-conf.json: |{"name": "cbr0","cniVersion": "0.3.1","plugins": [{"type": "flannel","delegate": {"hairpinMode": true,"isDefaultGateway": true}},{"type": "portmap","capabilities": {"portMappings": true}}]}net-conf.json: |{"Network": "10.244.0.0/16","EnableNFTables": false,"Backend": {"Type": "vxlan"}}
---
apiVersion: apps/v1
kind: DaemonSet
metadata:name: kube-flannel-dsnamespace: kube-systemlabels:tier: nodeapp: flannelk8s-app: flannel
spec:selector:matchLabels:app: flanneltemplate:metadata:labels:tier: nodeapp: flannelspec:affinity:nodeAffinity:requiredDuringSchedulingIgnoredDuringExecution:nodeSelectorTerms:- matchExpressions:- key: kubernetes.io/osoperator: Invalues:- linuxhostNetwork: truepriorityClassName: system-node-criticaltolerations:- operator: Existseffect: NoScheduleserviceAccountName: flannelinitContainers:- name: install-cni-pluginimage: docker.io/flannel/flannel-cni-plugin:v1.6.0-flannel1command:- cpargs:- -f- /flannel- /opt/cni/bin/flannelvolumeMounts:- name: cni-pluginmountPath: /opt/cni/bin- name: install-cniimage: docker.io/flannel/flannel:v0.26.1command:- cpargs:- -f- /etc/kube-flannel/cni-conf.json- /etc/cni/net.d/10-flannel.conflistvolumeMounts:- name: cnimountPath: /etc/cni/net.d- name: flannel-cfgmountPath: /etc/kube-flannel/containers:- name: kube-flannelimage: docker.io/flannel/flannel:v0.26.1command:- /opt/bin/flanneldargs:- --ip-masq- --kube-subnet-mgrresources:requests:cpu: "100m"memory: "50Mi"securityContext:privileged: falsecapabilities:add: ["NET_ADMIN", "NET_RAW"]env:- name: POD_NAMEvalueFrom:fieldRef:fieldPath: metadata.name- name: POD_NAMESPACEvalueFrom:fieldRef:fieldPath: metadata.namespace- name: EVENT_QUEUE_DEPTHvalue: "5000"volumeMounts:- name: runmountPath: /run/flannel- name: flannel-cfgmountPath: /etc/kube-flannel/- name: xtables-lockmountPath: /run/xtables.lockvolumes:- name: runhostPath:path: /run/flannel- name: cni-pluginhostPath:path: /opt/cni/bin- name: cnihostPath:path: /etc/cni/net.d- name: flannel-cfgconfigMap:name: kube-flannel-cfg- name: xtables-lockhostPath:path: /run/xtables.locktype: FileOrCreate
EOFkubectl apply -f flannel.yaml

检查证书有效期

kubeadm certs check-expiration[check-expiration] Reading configuration from the cluster...
[check-expiration] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'CERTIFICATE                EXPIRES                  RESIDUAL TIME   CERTIFICATE AUTHORITY   EXTERNALLY MANAGED
admin.conf                 Oct 27, 2124 10:08 UTC   99y             ca                      no      
apiserver                  Oct 27, 2124 10:08 UTC   99y             ca                      no      
apiserver-etcd-client      Oct 27, 2124 10:08 UTC   99y             etcd-ca                 no      
apiserver-kubelet-client   Oct 27, 2124 10:08 UTC   99y             ca                      no      
controller-manager.conf    Oct 27, 2124 10:08 UTC   99y             ca                      no      
etcd-healthcheck-client    Oct 27, 2124 10:08 UTC   99y             etcd-ca                 no      
etcd-peer                  Oct 27, 2124 10:08 UTC   99y             etcd-ca                 no      
etcd-server                Oct 27, 2124 10:08 UTC   99y             etcd-ca                 no      
front-proxy-client         Oct 27, 2124 10:08 UTC   99y             front-proxy-ca          no      
scheduler.conf             Oct 27, 2124 10:08 UTC   99y             ca                      no      
super-admin.conf           Oct 27, 2124 10:08 UTC   99y             ca                      no      CERTIFICATE AUTHORITY   EXPIRES                  RESIDUAL TIME   EXTERNALLY MANAGED
ca                      Oct 27, 2124 10:08 UTC   99y             no      
etcd-ca                 Oct 27, 2124 10:08 UTC   99y             no      
front-proxy-ca          Oct 27, 2124 10:08 UTC   99y             no 

至此使用自编译的kubeadm,证书有效期100年搭建k8s集群完成,仅供参考。

此种方式搭建k8s集群,仍然使用docker作为runtime运行时,和直接使用containerd作为runtime性能上稍差,相对来说docker生态更加完善,使用习惯不变。

http://www.lryc.cn/news/490709.html

相关文章:

  • Python浪漫之画明亮的月亮
  • 【前端】JavaScript 中的函数嵌套:从基础到深度应用的全面指南
  • 微信小程序条件渲染与列表渲染的全面教程
  • 全面击破工程级复杂缓存难题
  • python安装包中的一些问题(三):加载 matplotlib 的过程中,调用了 Pillow(PIL 库)时发生了错误
  • AWTK-WEB 快速入门(1) - C 语言应用程序
  • 【Spiffo】环境配置:VScode+Windows开发环境
  • 贴代码框架PasteForm特性介绍之file
  • 2024年 数模美赛 B题 潜水艇
  • ChatGPT 与其他 AI 技术在短视频营销中的技术应用与协同策略
  • H.265流媒体播放器EasyPlayer.js播放器提示MSE不支持H.265解码可能的原因
  • 电脑自动关机时间如何定?Wise Auto Shutdown 设置关机教程
  • 笔记mfc11
  • 【探寻密码的奥秘】-001:解开密码的神秘面纱
  • ElasticSearch7.x入门教程之集群安装(一)
  • c++ 笔记
  • 【腾讯云】AI驱动TDSQL-C Serveress 数据库技术实战营-如何是从0到1体验电商可视化分析小助手得统计功能,一句话就能输出目标统计图
  • 10 —— Webpack打包模式
  • 【ArcGIS微课1000例】0132:从多个GIS视角认识与攀登珠穆朗玛峰
  • vue2 - 20.json-server
  • echarts4r 教程1:Get Started
  • 蚁群算法(Ant Colony Optimization, ACO)
  • 使用IDEA构建springboot项目+整合Mybatis
  • 苹果系统中利用活动监视器来终止进程
  • 宝塔安装雷池网站防护
  • JavaScript完整原型链
  • Vue 内置组件 keep-alive 中 LRU 缓存淘汰策略和实现
  • 李宏毅机器学习课程知识点摘要(14-18集)
  • 《AI大模型开发笔记》Faster-Whisper 免费开源的高性能语音识别模型
  • 蓝队基础,网络七杀伤链详解