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

embedded/2024/11/25 14:10:45/

环境说明

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.ppmy.cn/embedded/140401.html

相关文章

Mac配置maven环境及在IDEA中配置Maven

Mac配置maven环境及在IDEA中配置Maven 1. 介绍 Maven是一款广泛用于Java等JVM语言项目的工具&#xff0c;它以项目对象模型&#xff08;POM&#xff09;为基础进行项目管理&#xff0c;通过POM文件来定义项目信息和依赖关系。同时&#xff0c;它也是构建自动化工具&#xff0…

Sparrow系列拓展篇:消息队列和互斥锁等IPC机制的设计

前言 笔者这几天利用空闲时间为Sparrow添加了消息队列和互斥锁&#xff0c;已经有十余天没有更过文章了&#xff0c;今天下笔想写一写博客&#xff0c;遂继续为Sparrow更新一篇拓展篇。 其实也没什么好讲的&#xff0c;信号量、消息队列、互斥锁这些IPC机制都大差不差&#x…

DVWA 在 Windows 环境下的部署指南

目录预览 一、靶场介绍二、前置准备1. 环境准备2.靶场下载 三、安装步骤1.配置Phpstudy2.配置数据库3.配置DVWA4.登入DVWA靶场 四、参考链接 一、靶场介绍 DVWA 一共包含了十个攻击模块&#xff0c;分别是&#xff1a; Brute Force&#xff08;暴力&#xff08;破解&#xff…

GoZero接口用postman调用字段类型不够并优化:如何解决数据库插入与更新失败问题

在开发过程中&#xff0c;我们常常会遇到因字段类型不匹配导致的数据库插入失败的问题。本文将探讨一个具体的错误案例&#xff0c;并提供一种优化方案&#xff0c;帮助开发者更好地处理类似的问题。 ## 错误背景 在使用 GoZero 框架开发接口时&#xff0c;我们遇到了如下错误…

埃文科技携手河南企业代表团亮相第十九届广州中博会

2024年11月15日-18日&#xff0c;第十九届中国国际中小企业博览会&#xff08;以下简称“中博会”)在广州举行。郑州埃文科技有限公司携手河南企业代表团&#xff0c;以“聚焦新型工业化发展新质生产力”为主题&#xff0c;亮相中博会&#xff0c;展现河南省在数字化转型和新型…

C 语言变量说明符

目录 1.const 2.static 3.auto 4.extern 5.register 6.volatile 7.restrict C 语言允许声明变量的时候&#xff0c;加上一些特定的说明符&#xff08;specifier&#xff09;&#xff0c;为编译器提供变量行为的额外信息。它的主要作用是帮助编译器优化代码&#xff0c;有…

谷粒商城-消息队列Rabbitmq

RabbitMq参考文档 在谷粒商城项目中使用消息队列主要有以下几个重要原因&#xff1a; 异步处理提高性能 场景示例&#xff1a;在订单系统中&#xff0c;当用户提交订单后&#xff0c;系统需要完成多个操作&#xff0c;如更新库存、生成订单记录、发送订单通知等。如果这些操作…

谷歌云无法ssh登录(修改sshd_config也不行)

sudo -i vi /etc/ssh/sshd_config passwd root /etc/init.d/ssh restart service sshd restart 这是网站大部分教程讲的&#xff0c;但是我实际试了还是连不上 参考https://linux.do/t/topic/260732/15 原来/etc/ssh/sshd_config.d/下面有个60开头的文件&#xff0c;也需…