OpenEular23.09(欧拉)操作系统为企业搭建独立的K8S集群环境,详细流程+截图
一.环境;
win10,vmware16 pro,openeular23.09,linux内核 6.4.0-10.1.0.20.oe2309.x86_64,
docker-engine 2:18.09.0-328,kubernetes 1.25.3,containerd 1.6.22,calico v3.25
集群模式:一主二从
| 主机名 | IP | 角色 | CPU | 内存 | 硬盘 |
| k8s-master01 | 192.168.91.100 | master | 4C | 4G | 40G |
| k8s-worker02 | 192.168.91.101 | worker(node) | 4C | 4G | 40G |
| k8s-worker03 | 192.168.91.102 | worker(node) | 4C | 4G | 40G |
# 查看linux内核版本
uname -r

二.openEuler集群搭建;
单机版operEuler安装及配置按下面链接逐步操作即可;
VMware16 pro 安装openEuler-23.09-x86_64,详细操作流程+详图。-CSDN博客文章浏览阅读174次,点赞5次,收藏4次。那么这个空间设置成内存的2倍大小。点击IPv4设置--手动--添加--设置ip--设置DNS服务器,最后点击--“保存”;首先选中--“本地标准磁盘”,存储配置--自定义分区,点击--“完成”;在--主机名--设置主机名:(例如k8s-master01),点击--点击+,设置--挂载点/boot--期望容量,点击--添加挂载点;点击--+--挂载点swap--期望容量,点击--“添加挂载点”;默认选择--亚洲--上海,并调整日期和时间,点击--“完成”;设备类型--确认--LVM,卷组--选择“修改”;https://blog.csdn.net/shanxiderenheni/article/details/135247321
1.节点克隆;
搭建好主节点k8s-master01,先关机,再按照下图右键操作,克隆出两个工作节点k8s-worker02和k8s-worker03;(此时,三台虚拟机的账户,密码,IP,网络等信息都是一样的)

2.修改两个工作节点的主机名和IP;
hostnamectl set-hostname k8s-worker02

修改k8s-woker02节点的IP;
定位到指定目录命令:
cd /etc/sysconfig/network-scripts
编辑命令:
vim ifcfg-ens33
k8s-woker02:192.168.91.101





k8s-worker03节点的操作与上面相同;
k8s-worker03:192.168.91.102

3.网络相关重要配置检查一遍,一般没啥问题,眼过一遍即可;
两个worker节点都看一遍;





三.Xshell远程登录三台euler服务器;





四.全部集群主机修改hosts,完成主机名与IP的映射;
vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.91.100 k8s-master01
192.168.91.101 k8s-worker02
192.168.91.102 k8s-worker03




五.关闭全部主机防火墙;
关闭防火墙:
systemctl stop firewalld
禁止开机自启:
systemctl disable firewalld
查看防火墙状态:
systemctl status firewalld


六.所有主机关闭selinux;
sed -ri 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
cat /etc/selinux/config

# 查看本机selinux状态
sestatus

修改SELinux配置需要所有主机重启操作系统。

七.所有主机同步时间配置;
最小化安装系统需要安装ntpdate软件,此处安装的是服务器版本,带有update软件,直接使用即可;
安装命令:
yum -y install ntpdate

编辑同步时间规则命令:
# 创建计划任务
crontab -e

0 */1 * * * /usr/sbin/ntpdate time1.aliyun.com


# 启动时间同步,一个小时同步一次
ntpdate time1.aliyun.com

八.所有主机配置内核转发及网桥过滤;
开启内核路由转发命令:
vim /etc/sysctl.conf

(截图中命令显示两次,是我测试命令可用后,二次截图的操作)

配置内核参数,将桥接的IPv4流量传递到iptables的链的命令:(创建新文件+编辑内容)
cat <<EOF >/etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
vm.swappiness=0
EOF
# 二次编辑,加入"net.ipv4.ip_forward = 1"
vim /etc/sysctl.d/k8s.conf



执行该命令,如果不执行就会在应用k8s.conf时出现加载错误;
# 加载br_netfilter模块
modprobe br_netfilter

# 查看是否加载
lsmod | grep br_netfilter

使用新添加配置文件生效;
sysctl -p /etc/sysctl.d/k8s.conf
或下面命令:
# 使其生效
sysctl --system


九.所有主机安装ipset及ipvsadm;
yum -y install ipset ipvsadm

回车,安装过程如下;


配置ipvsadm模块加载方式,添加需要加载的模块;
cat > /etc/sysconfig/modules/ipvs.module <<EOF
#!/bin/bash
modprobe -- ip_vs
modprobe -- ip_vs_sh
modprobe -- ip_vs_rr
modprobe -- ip_vs_wrr
modprobe -- nf_conntrack
EOF

授权、运行、检查是否加载;
chmod 755 /etc/sysconfig/modules/ipvs.module && bash /etc/sysconfig/modules/ipvs.module && lsmod | grep -e ip_vs -e nf_conntrack


十.关闭SWAP分区;
方法一:
# 如果有的话,关闭swap分区
swapoff -a# 永久关闭swap分区,注释掉fstab中包含swap的这一行
vim /etc/fstab
# /dev/mapper/centos-swap swap swap defaults 0 0
方法二:
#实时动态关闭
swapoff -a #禁止重启后自动开启
sed -i '/ swap / s/^/#/' /etc/fstab
本案例采用方法二;




十一.所有主机重启;
reboot



十二.所有主机docker安装;
1.查看是否存在docker软件;
yum list | grep docker

2.安装docker;
dnf install docker

3.设置docker开机启动并启动;
systemctl enable --now docker

4.查看docker版本;
docker version

十三.k8s软件安装;
1.所有主机安装k8s依赖,连接跟踪;
dnf install conntrack


2.k8s-master01节点安装;
dnf install -y kubernetes-kubeadm kubernetes-kubelet kubernetes-master




3.k8s-worker02和k8s-worker03两个节点安装;
dnf install -y kubernetes-kubeadm kubernetes-kubelet kubernetes-node
k8s-worker02


k8s-worker03


4.所有主机设置开机自启kubelet;
systemctl enable kubelet
K8S通过kubeadm安装出来以后都是以Pod方式存在,即底层是以容器方式运行,所以kubelet必须设置开机自启。

5.所有主机现在启动kubelet.service;
systemctl start kubelet.service

6.所有主机查看kubelet运行状态;
systemctl status kubelet



所有主机重启kubelet;
systemctl restart kubelet

排查 hostname、etc/hosts等均正常。
十四.k8s集群初始化master节点(只在k8s-master01节点操作初始化命令);
kubeadm init --node-name=k8s-master01 \
--image-repository=registry.aliyuncs.com/google_containers \
--kubernetes-version v1.25.3 \
--cri-socket=unix:///var/run/cri-dockerd.sock \
--apiserver-advertise-address=192.168.91.100 \
--pod-network-cidr=10.244.0.0/16 \
--service-cidr=10.96.0.0/12
错误一:“crictl not found in system path”;
(重要提醒:此处只在master节点安装crictl,后面在k8s集群初始化完成后,执行worker节点加入master时,报错worker找不到crictl,所以全部主机都必须安装crictl。)

需要安装crictl工具;(建议所有主机都要安装crictl,后面都会用到)
yum install -y crictl

错误二:“socat not found in system path”;

需要安装socat工具;
yum install -y socat

错误三:[ERROR CRI]: container runtime is not running: output: time="2023-12-29T08:16:11+08:00" level=fatal msg="unable to determine runtime API version: rpc error: code = Unavailable desc = connection error: desc = \"transport: Error while dialing dial unix /var/run/cri-dockerd.sock: connect: no such file or directory\""
, error: exit status 1

(重点注意:此处只在master节点安装containerd,推荐在所有节点都安装containerd,因为worker节点加入master时,需要用到containerd。)
| 关于containerd的介绍: |
|---|
| 1.根据k8s官网的介绍,kubernets 自v1.24.0 后,移除了docker.shim(k8s集成的docker),替换采用 containerd 作为容器运行时。因此需要安装 containerd 而containerd是docker的子项目,现在他俩分开了,所以可以单独安装containerd。 |
| 2.常用的容器运行时有docker、containerd、CRI-O等 containerd是一个CRI(Container Runtime Interface)组件,在容器运行时调用containerd组件来创建、运行、销毁容器等 CRI组件遵循OCI规范,通过runc实现与操作系统内核的交互,然后实现创建和运行容器 docker使用containerd作为运行时,k8s使用containerd、CRI-O等。 |
| 3.CRI Container Runtime Interface 容器运行时接口 container runtime is not running 容器运行时未启动 validate service connection 无效的服务连接 CRI v1 runtime API is not implemented for endpoint “unix:///var/run/containerd/containerd.sock” 容器运行时接口 v1 运行时 接口 没有实现节点文件sock,应该就是此文件未找到。 |
问题定位:
1.“container runtime is not running”,containerd服务未启动,查阅containerd运行状态;
systemctl status containerd

2.提示未找到containerd.service,需要安装containerd.service;
yum install -y containerd


3.yum安装containerd失败原因分析:
(1)k8s 1.24之后弃用了docker-shim。
dockershim 的作用是 Kubernetes 通过 CRI 来操作 Docker,所以Kubernetes 任何的功能变动或 Docker 有任何的功能特性变更,dockershim 代码必须加以改动保证能够支持相关的变更(维护特别不方便)。
另外,Docker 的底层运行时是 containerd(大家装docker的时候应该也会发现有containerd这样几个东西),最终都是要调用 containerd且 containerd 自身也支持 CRI 。那为什么要先绕过一层 Docker 呢?是不是可以直接通过 CRI 跟 Containerd 进行交互呢?这也就造成了现在 Kubernetes 社区弃用 dockershim的原因。
(2)linux操作系统systemd的服务管理。
系统服务在/usr/lib/systemd/system目录下,名字为*.service之类的文件,systemctl可以通过文件名管理服务。这就是为什么有些systemctl 可以管理一些二进制启动的服务,linux的3.10的内核以后直接后台运行二进制程序显然不够优雅。
(3)主流的平台platform有x86(amd),arm(aarch)等等,操作系统也是分linux/windows的。
参考cpu架构,如果不熟悉的话,还是不好记住的,特别是amd/arm这种容易混。特别注意的是,用ctr命令拉取、导入、导出镜像,是需要指定平台的,否则有时候会报相关错误,ctr也支持全平台,但是文件就比较大了。
(4)containerd的工具为ctr,k8s管理containerd的工具为crictl。
ctr是containerd的工具,它运行时,需要在ctr 紧后加入-n namespace。例如k8s的镜像是放在k8s.io的命名空间下的,你直接用ctr查看,是看不到镜像的,你需要这样才能看到:ctr -n k8s.io images list。但是可以用crictl直接查看到k8s运行的服务的镜像。
4.用二进制文件安装containerd;
(1)下载地址(本测试用的是1.6.22版本,其他版本自行选择下载);
https://github.com/containerd/containerd/releases/tag/v1.6.22
https://github.com/containerd/containerd/releases/tag/v1.6.22

(2)上传,解压“cri-containerd-1.6.22-linux-amd64.tar.gz”;
上传containerd压缩包到k8s-master01节点,位置自选;

(3)解压containerd压缩包到“/usr/bin/”,或“/usr/local/bin/”;
因为这两个目录都具有系统的环境变量,可以直接运行。比如ssh命令其实就在/usr/bin/ssh
①本案例是解压到“/usr/local/bin/”,(因为该路径本来是空的,万一解压失败,回退也方便清理);

tar -zxvf cri-containerd-1.6.22-linux-amd64.tar.gz -C /usr/local/bin/



-------------------由于参考资料不完整--------------走的一段弯路start------------------记录一下-------------
赋予它们可执行权限,4=读,2=写,1=可执行,加一起就是他的权限。
chmod 0755 /usr/bin/containerd*
chmod 0755 /usr/bin/crictl
chmod 0755 /usr/bin/ctd-decoder
chmod 0755 /usr/bin/runc
chmod 0755 /usr/bin/ctr



-----------------------------------------------------------弯路end---------------------------------------------------------
正确方法如下:

etc目录:主要为containerd服务管理配置文件及cni虚拟网卡配置文件;
opt目录:主要为gce环境中使用containerd配置文件及cni插件;
usr目录:主要为containerd运行时的二进制文件,包含runc;
②拷贝二进制可执行文件到$PATH中;
[root@k8s-master01 /]# cd /usr/local/bin
[root@k8s-master01 bin]# ll
总计 16
-rw-r--r-- 1 root root 682 7月28日 03:48 cri-containerd.DEPRECATED.txt
drwxr-xr-x 3 root root 4096 12月29日 11:11 etc
drwxr-xr-x 3 root root 4096 12月29日 11:11 opt
drwxr-xr-x 3 root root 4096 7月28日 03:45 usr
[root@k8s-master01 bin]# ls usr/local/bin
containerd containerd-shim containerd-shim-runc-v1 containerd-shim-runc-v2 containerd-stress crictl critest ctd-decoder ctr
[root@k8s-master01 bin]# ls /usr/local/bin
cri-containerd.DEPRECATED.txt etc opt usr
[root@k8s-master01 bin]# cp usr/local/bin/* /usr/local/bin/
[root@k8s-master01 bin]# ls /usr/local/bin
containerd containerd-shim containerd-shim-runc-v1 containerd-shim-runc-v2 containerd-stress cri-containerd.DEPRECATED.txt crictl critest ctd-decoder ctr etc opt usr
# 方法一:先进入根目录 cd /usr/local/bin 再执行下面的命令
cp usr/local/bin/* /usr/local/bin/

# 方法二:在任意目录执行下面的命令,路径都是从根目录开始计算
cp /usr/local/bin/usr/local/bin/* /usr/local/bin/
containerd 的安装包中一共有五个文件,通过上面的命令它们被安装到了 /usr/local/bin 目录中:
containerd:即容器的运行时,以 gRPC 协议的形式提供满足 OCI 标准的 API
containerd-release:containerd项目的发行版发布工具
containerd-stress:containerd压力测试工具
containerd-shim:这是每一个容器的运行时载体,我们在 docker 宿主机上看到的 shim 也正是代表着一个个通过调用 containerd 启动的 docker 容器。
ctr:它是一个简单的 CLI 接口,用作 containerd 本身的一些调试用途,投入生产使用时还是应该配合docker 或者 cri-containerd 部署。
赋予它们可执行权限,4=读,2=写,1=可执行,加一起就是他的权限。
正确命令如下:
chmod 0755 /usr/bin/containerd*
chmod 0755 /usr/bin/crictl
chmod 0755 /usr/local/bin/ctd-decoder
chmod 0755 /usr/bin/runc
chmod 0755 /usr/local/bin/ctr

③把上面解压的这个文件containerd.service,放到systemd的目录下:"/usr/lib/systemd/system/";
解压文件完整根路径如下:
"/usr/local/bin/etc/systemd/system/containerd.service"

mv /usr/local/bin/etc/systemd/system/containerd.service /usr/lib/systemd/system/

④给containerd.service赋予权限;
chmod 0755 /usr/lib/systemd/system/containerd.service

如果你不想每次使用crictl都带一行类似下面这样的参数,
crictl --image-endpoint unix:///var/run/containerd/containerd.sock
那么你就执行下面的命令:
cat >>/etc/crictl.yaml <<EOF
runtime-endpoint: unix:///var/run/containerd/containerd.sock
image-endpoint: unix:///var/run/containerd/containerd.sock
timeout: 10
debug: false
EOF

(4)master节点启动containerd;
a.查询containerd运行状态:
systemctl status containerd
b.启动containerd命令:
systemctl daemon-reloadsystemctl enable containerdsystemctl start containerd

十五.主节点k8s-master01执行集群初始化;
# k8s集群初始化
kubeadm init --node-name=k8s-master01 \
--image-repository=registry.aliyuncs.com/google_containers \
--kubernetes-version v1.25.3 \
--cri-socket=unix:///var/run/cri-dockerd.sock \
--apiserver-advertise-address=192.168.91.100 \
--pod-network-cidr=10.244.0.0/16 \
--service-cidr=10.96.0.0/12

# 如果初始化失败,可以重置;
kubeadm reset --cri-socket unix:///var/run/cri-docker.sock

但是切换到这个目录,发现目录是空的。(未截图)
1.查看kubelet启动日志;
# 检查journal日志
journalctl -u kubelet --no-pager
报错现象:kubelet 日志报 network plugin is not ready: cni config uninitialized
解决方法:网络插件(flannel 或者 calico)没有安装或者安装失败。

2.安装部署网络插件(master节点上);
必须安装网络组件否则k8s各个节点都是Noready状态;
calico和flannel二选一(本次安装使用的是flannel网路插件)
在此处下载 kube-flannel.yml;
Releases · flannel-io/flannel · GitHubflannel is a network fabric for containers, designed for Kubernetes - Releases · flannel-io/flannel
https://github.com/flannel-io/flannel/releases
直接apply: kubectl apply -f kube-flannel.yml
也可直接复制下面的命令:
cat > kube-flannel.yml << EOF
---
kind: Namespace
apiVersion: v1
metadata:name: kube-flannellabels:k8s-app: flannelpod-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
- apiGroups:- networking.k8s.ioresources:- clustercidrsverbs:- list- watch
---
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-flannel
---
apiVersion: v1
kind: ServiceAccount
metadata:labels:k8s-app: flannelname: flannelnamespace: kube-flannel
---
kind: ConfigMap
apiVersion: v1
metadata:name: kube-flannel-cfgnamespace: kube-flannellabels: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","Backend": {"Type": "vxlan"}}
---
apiVersion: apps/v1
kind: DaemonSet
metadata:name: kube-flannel-dsnamespace: kube-flannellabels: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.2.0command:- cpargs:- -f- /flannel- /opt/cni/bin/flannelvolumeMounts:- name: cni-pluginmountPath: /opt/cni/bin- name: install-cniimage: docker.io/flannel/flannel:v0.22.3command:- 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.22.3command:- /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
EOF

flannel 的pod启动正常后,如果节点还是Notready,需要安装kubernetes-cni
yum install -y kubernetes-cnils -lh /opt/cni/bin


3.检测主机环境是否达到集群的要求,可根据结果提示进行逐一排除故障;
kubeadm init --dry-run


下面的输出结果很重要,根据提示操作,应该就可以启动k8s集群了;
Your Kubernetes control-plane has initialized successfully!To start using your cluster, you need to run the following as a regular user:mkdir -p $HOME/.kubesudo cp -i /etc/kubernetes/tmp/kubeadm-init-dryrun2893094232/admin.conf $HOME/.kube/configsudo chown $(id -u):$(id -g) $HOME/.kube/configAlternatively, if you are the root user, you can run:export KUBECONFIG=/etc/kubernetes/admin.confYou should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:https://kubernetes.io/docs/concepts/cluster-administration/addons/Then you can join any number of worker nodes by running the following on each as root:kubeadm join 192.168.91.100:6443 --token zvm9d0.fzrnxmnb126pflg2 \--discovery-token-ca-cert-hash sha256:a8813f618c6155d3284fdc8aa7c4f896399c61d896299425d37747f12d2e3fb0
记得保存好最后的 kubeadm join的信息node节点加入集群需要token!!!
不然要执行生成token;
kubeadm token create --print-join-command
#利用kubeadm命令重新生成token,node 节点加入集群需要token
#普通用户执行下面命令;每次启动自动加载$HOME/.kube/config下的密钥配置文件(K8S自动行为);
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/tmp/kubeadm-init-dryrun2893094232/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config#命令的含义:Kubectl 是一个命令行接口,用于对 Kubernetes 集群运行命令。
#Kubectl 在 $HOME/.kube 目录中寻找一个名为 config 的文件。
#你可以通过设置环境变量 KUBECONFIG 或设置 --kubeconfig 参数指定其它 kubeconfig 文件
#当集群初始化成功后,要使 kubectl 适用于非 root 用户,则需要运行以下命令,这些命令也是 kubeadm init输出的一部分
#即创建.kube目录 -> 拷贝配置文件 -> 用户授权#当然,如果你是 root 用户,则可以直接添加环境变量:
执行 export KUBECONFIG=/etc/kubernetes/admin.confkubectl cluster-info
#查看一下是否成功,等待一会儿,同时可以发现像etc,controller,scheduler等组件都以pod的方式安装成功


cp -i /etc/kubernetes/tmp/kubeadm-init-dryrun2893094232/admin.conf /etc/kubernetes/admin.conf
4.【kubectl get nodes】查看当前节点异常“The connection to the server 192.168.91.100:6443 was refused - did you specify the right host or port?”;
kubectl get nodes
报错:The connection to the server 192.168.91.100:6443 was refused - did you specify the right host or port?

mkdir /etc/containerdcontainerd config default > /etc/containerd/config.toml

"/etc/containerd/config.toml"这个文件好像没啥用,还是删了。
rm -rf /etc/containerd/config.tomlsystemctl restart containerd
Kubeadm初始化依然报错:
“[ERROR CRI]: container runtime is not running:”
正确操作如下:
(1)确保下面命令执行且生效,"admin.conf......";
#普通用户执行下面命令;每次启动自动加载$HOME/.kube/config下的密钥配置文件(K8S自动行为);
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/tmp/kubeadm-init-dryrun2893094232/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config#命令的含义:Kubectl 是一个命令行接口,用于对 Kubernetes 集群运行命令。
#Kubectl 在 $HOME/.kube 目录中寻找一个名为 config 的文件。
#你可以通过设置环境变量 KUBECONFIG 或设置 --kubeconfig 参数指定其它 kubeconfig 文件
#当集群初始化成功后,要使 kubectl 适用于非 root 用户,则需要运行以下命令,这些命令也是 kubeadm init输出的一部分
#即创建.kube目录 -> 拷贝配置文件 -> 用户授权#当然,如果你是 root 用户,则可以直接添加环境变量:
export KUBECONFIG=/etc/kubernetes/admin.confecho "KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bashrc && source ~/.bashrc# 查看当前节点
kubectl get nodes
(2)所有主机重置k8s集群;
kubeadm reset


(3)所有主机删除$HOME/.kube;
rm -rf $HOME/.kube






# master节点执行k8s集群初始化命令
# 使用docker容器
kubeadm init --node-name=k8s-master01 \
--image-repository=registry.aliyuncs.com/google_containers \
--kubernetes-version v1.25.3 \
--cri-socket=unix:///var/run/cri-dockerd.sock \
--apiserver-advertise-address=192.168.91.100 \
--pod-network-cidr=10.244.0.0/16 \
--service-cidr=10.96.0.0/12# 使用containerd作为容器,不再使用docker
kubeadm init --node-name=k8s-master01 \
--image-repository=registry.aliyuncs.com/google_containers \
--kubernetes-version v1.25.3 \
--apiserver-advertise-address=192.168.91.100 \
--pod-network-cidr=10.244.0.0/16 \
--service-cidr=10.96.0.0/12# 如果初始化失败,可以重置(所有主机)
kubeadm reset
(4)master节点执行 k8s初始化失败:The kubelet is not running;

# 如果初始化失败,必须重置(所有主机)
kubeadm reset
不重置,会提示.yaml配置文件已经存在,无法初始化;


(5)重置后,k8s集群初始化提示超时,[kubelet-check] Initial timeout of 40s passed;



(6)修改/lib/systemd/system/kubelet.service;
this might take a minute or longer if the control plane images have to be pulled #1023(https://github.com/kubernetes/kubeadm/issues/1023), 尝试一下,没想到竟然成功了!方法就是修改/lib/systemd/system/kubelet.service,添加kubelet启动参数如下:
[Service]
ExecStart=/usr/bin/kubelet --kubeconfig=/etc/kubernetes/kubelet.conf --config=/var/lib/kubelet/config.yaml
…
然后,重启计算机,所有主机执行sudo kubeadm reset 后重新执行下面初始化命令;
kubeadm init --node-name=k8s-master01 \
--image-repository=registry.aliyuncs.com/google_containers \
--kubernetes-version v1.25.16 \
--apiserver-advertise-address=192.168.91.100 \
--pod-network-cidr=10.244.0.0/16 \
--service-cidr=10.96.0.0/12
# 查看原来内容
cat /lib/systemd/system/kubelet.service

# 查阅"/etc/kubernetes/kubelet.conf"内容
cat /etc/kubernetes/kubelet.conf

# 修改/lib/systemd/system/kubelet.service内容
# [Service]
# ExecStart=/usr/bin/kubelet --kubeconfig=/etc/kubernetes/kubelet.conf --config=/var/lib/kubelet/config.yamlvim /lib/systemd/system/kubelet.service
然后,重启计算机,所有主机执行sudo kubeadm reset 后重新执行sudo kubeadm init。

重启master节点后,k8s集群初始化仍然报错;

(7)所有主机修改镜像仓库和添加k8s阿里云YUM软件源;
# 修改镜像仓库
cat > /etc/docker/daemon.json << EOF
{"registry-mirrors": ["https://b9pmyelo.mirror.aliyuncs.com"]
}
EOF
# 添加k8s阿里云YUM软件源
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

(8)所有主机修改/etc/docker/daemon.json内容,重启 docker;
vim /etc/docker/daemon.json



# 所有主机都重启docker
systemctl daemon-reload && systemctl restart docker


(9)主要错误信息跟踪:
Unfortunately, an error has occurred:
timed out waiting for the condition
This error is likely caused by:
- The kubelet is not running
- The kubelet is unhealthy due to a misconfiguration of the node in some way (required cgroups disabled)
If you are on a systemd-powered system, you can try to troubleshoot the error with the following commands:
- 'systemctl status kubelet'
- 'journalctl -xeu kubelet'
# 查看日志
journalctl -xeu kubelet

日志文件中的错误主要有四种:
①找不到节点;
12月 30 07:32:36 k8s-master01 kubelet[5883]: E1230 07:32:36.274681 5883 kubelet.go:2448] "Error getting node" err="node \"k8s-master01\" not found"
②获取不到节点信息;
12月 30 07:32:37 k8s-master01 kubelet[5883]: E1230 07:32:37.142275 5883 eviction_manager.go:256] "Eviction manager: failed to get summary stats" err="failed to get node info: node \">
③Unable to register node with API server;
12月 30 07:32:37 k8s-master01 kubelet[5883]: I1230 07:32:37.927673 5883 kubelet_node_status.go:70] "Attempting to register node" node="k8s-master01"
12月 30 07:32:37 k8s-master01 kubelet[5883]: E1230 07:32:37.928739 5883 kubelet_node_status.go:92] "Unable to register node with API server" err="Post \"https://192.168.91.100:6443/a>
④获取不到pause镜像;
12月 30 07:32:38 k8s-master01 kubelet[5883]: E1230 07:32:38.966359 5883 remote_runtime.go:222] "RunPodSandbox from runtime service failed" err="rpc error: code = Unknown desc = faile>
12月 30 07:32:38 k8s-master01 kubelet[5883]: E1230 07:32:38.966484 5883 kuberuntime_sandbox.go:71] "Failed to create sandbox for pod" err="rpc error: code = Unknown desc = failed to >
12月 30 07:32:38 k8s-master01 kubelet[5883]: E1230 07:32:38.966536 5883 kuberuntime_manager.go:772] "CreatePodSandbox for pod failed" err="rpc error: code = Unknown desc = failed to >
12月 30 07:32:38 k8s-master01 kubelet[5883]: E1230 07:32:38.966880 5883 pod_workers.go:965] "Error syncing pod, skipping" err="failed to \"CreatePodSandbox\" for \"kube-controller-ma>
(10)所有主机配置kubernetes源;
# 此操作会覆盖 /etc/yum.repos.d/kubernetes.repo 中现存的所有配置
cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://pkgs.k8s.io/core:/stable:/v1.28/rpm/
enabled=1
gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.28/rpm/repodata/repomd.xml.key
#exclude=kubelet kubeadm kubectl cri-tools kubernetes-cni
EOF


# 执行查看错误日志命令
journalctl -xeu kubelet

12月 30 08:36:39 k8s-master01 kubelet[9046]: E1230 08:36:39.877844 9046 controller.go:144] failed to ensure lease exists, will retry in 7s, error: Get "https://192.168.91.100:6443/ap>
12月 30 08:36:39 k8s-master01 kubelet[9046]: I1230 08:36:39.944114 9046 kubelet_node_status.go:70] "Attempting to register node" node="k8s-master01"
12月 30 08:36:39 k8s-master01 kubelet[9046]: E1230 08:36:39.944382 9046 kubelet_node_status.go:92] "Unable to register node with API server" err="Post \"https://192.168.91.100:6443/a>
尝试网上的解决方案:添加pod-infra-container-image参数,但是添加该参数后仍然报错。
tee /etc/sysconfig/kubelet <<-EOF
KUBELET_EXTRA_ARGS="--pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.8"
EOF
执行k8s集群初始化命令,还是一样的错误信息。


12月 30 08:57:30 k8s-master01 kubelet[10298]: E1230 08:57:30.116956 10298 kubelet.go:2373] "Container runtime network not ready" networkReady="NetworkReady=false reason:NetworkPluginN>
Container runtime network not ready错误通常是由于网络配置不正确或网络插件未正确安装等原因引起的。通过检查网络插件、网络配置、重启kubelet服务、检查网络状态以及重启节点等步骤,我们可以解决这个问题。在解决问题之前,确保备份数据和配置,并确保有其他节点可以接管工作负载,以防止服务中断。
所有主机执行下面命令:
sysctl net.bridge.bridge-nf-call-iptables=1
# 重启kubelet
systemctl restart kubelet
# 查看kubelet状态
systemctl status kubelet

重置后,初始化还是报一样的错误。
master节点执行下面命令:
systemctl stop kubelet
docker stop $(docker ps -aq)
docker rm -f $(docker ps -aq)
systemctl stop docker
kubeadm reset
rm -rf $HOME/.kube /etc/kubernetes
rm -rf /var/lib/cni/ /etc/cni/ /var/lib/kubelet/*
iptables -F && iptables -t nat -F && iptables -t mangle -F && iptables -X
systemctl start docker
systemctl start kubelet#安装 calico 网络插件(没有高可用)
rm -f calico-3.13.1.yaml
wget -L https://kuboard.cn/install-script/calico/calico-3.13.1.yaml
kubectl apply -f calico-3.13.1.yaml

# 主节点master检测初始化环境
kubeadm init --dry-run


To start using your cluster, you need to run the following as a regular user:mkdir -p $HOME/.kubesudo cp -i /etc/kubernetes/tmp/kubeadm-init-dryrun3193660062/admin.conf $HOME/.kube/configsudo chown $(id -u):$(id -g) $HOME/.kube/configAlternatively, if you are the root user, you can run:export KUBECONFIG=/etc/kubernetes/admin.confYou should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:https://kubernetes.io/docs/concepts/cluster-administration/addons/Then you can join any number of worker nodes by running the following on each as root:kubeadm join 192.168.91.100:6443 --token 9m9vtr.f0bu4txbgap9l5ow \--discovery-token-ca-cert-hash sha256:6c34069547252d6321e27634b0f1c0caa2b85fe352f18b3c6242fddf4e5aba24
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/tmp/kubeadm-init-dryrun3193660062/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
export KUBECONFIG=/etc/kubernetes/admin.conf
cp -i /etc/kubernetes/tmp/kubeadm-init-dryrun3193660062/admin.conf /etc/kubernetes/admin.conf

所有主机重置后,master节点初始化k8s集群,还是一样的错误。
十六.k8s集群初始化成功;
1.下面方法可以解决containerd运行状态报错的问题(仅master主节点);
(1)master节点先删除“/etc/containerd/config.toml”文件;
rm /etc/containerd/config.toml

(2)master节点执行下面命令,重新生成“/etc/containerd/config.toml 文件”;
sudo containerd config default | sudo tee /etc/containerd/config.toml
sudo sed -i 's#SystemdCgroup = false#SystemdCgroup = true#g' /etc/containerd/config.toml
sudo sed -i 's#sandbox_image = "k8s.gcr.io/pause:3.6"#sandbox_image = "registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6"#g' /etc/containerd/config.toml
命令执行完之后,一定要检查一遍配置内容有没有改过来。


发现没改成功,手动修改:


(3)master节点重启containerd;
sudo systemctl restart containerd
(4)master节点查看containerd状态;
systemctl status containerd


(5)所有主机重置初始化;
kubeadm reset

(6)在master节点执行k8s集群初始化命令;
# master节点执行k8s集群初始化命令(指定k8s版本如果不存在,系统会推荐最优接近版本)
# 1.使用docker容器
kubeadm init --node-name=k8s-master01 \
--image-repository=registry.aliyuncs.com/google_containers \
--kubernetes-version v1.25.3 \
--cri-socket=unix:///var/run/cri-dockerd.sock \
--apiserver-advertise-address=192.168.91.100 \
--pod-network-cidr=10.244.0.0/16 \
--service-cidr=10.96.0.0/12# 2.使用containerd作为容器,不再使用docker(本案例使用这个命令)
kubeadm init --node-name=k8s-master01 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.25.16 \
--apiserver-advertise-address=192.168.91.100 \
--pod-network-cidr=10.244.0.0/16 \
--service-cidr=10.96.0.0/12
# 使用containerd作为容器,不再使用docker
kubeadm init --node-name=k8s-master01 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.25.16 \
--apiserver-advertise-address=192.168.91.100 \
--pod-network-cidr=10.244.0.0/16 \
--service-cidr=10.96.0.0/12


[root@k8s-master01 ~]# kubeadm init --node-name=k8s-master01 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.25.16 \
--apiserver-advertise-address=192.168.91.100 \
--pod-network-cidr=10.244.0.0/16 \
--service-cidr=10.96.0.0/12
[init] Using Kubernetes version: v1.25.16
[preflight] Running pre-flight checks
[preflight] Pulling images required for setting up a Kubernetes cluster
[preflight] This might take a minute or two, depending on the speed of your internet connection
[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'
[certs] Using certificateDir folder "/etc/kubernetes/pki"
[certs] Generating "ca" certificate and key
[certs] Generating "apiserver" certificate and key
[certs] apiserver serving cert is signed for DNS names [k8s-master01 kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 192.168.91.100]
[certs] Generating "apiserver-kubelet-client" certificate and key
[certs] Generating "front-proxy-ca" certificate and key
[certs] Generating "front-proxy-client" certificate and key
[certs] Generating "etcd/ca" certificate and key
[certs] Generating "etcd/server" certificate and key
[certs] etcd/server serving cert is signed for DNS names [k8s-master01 localhost] and IPs [192.168.91.100 127.0.0.1 ::1]
[certs] Generating "etcd/peer" certificate and key
[certs] etcd/peer serving cert is signed for DNS names [k8s-master01 localhost] and IPs [192.168.91.100 127.0.0.1 ::1]
[certs] Generating "etcd/healthcheck-client" certificate and key
[certs] Generating "apiserver-etcd-client" certificate and key
[certs] Generating "sa" key and public key
[kubeconfig] Using kubeconfig folder "/etc/kubernetes"
[kubeconfig] Writing "admin.conf" kubeconfig file
[kubeconfig] Writing "kubelet.conf" kubeconfig file
[kubeconfig] Writing "controller-manager.conf" kubeconfig file
[kubeconfig] Writing "scheduler.conf" kubeconfig file
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Starting the kubelet
[control-plane] Using manifest folder "/etc/kubernetes/manifests"
[control-plane] Creating static Pod manifest for "kube-apiserver"
[control-plane] Creating static Pod manifest for "kube-controller-manager"
[control-plane] Creating static Pod manifest for "kube-scheduler"
[etcd] Creating static Pod manifest for local etcd in "/etc/kubernetes/manifests"
[wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory "/etc/kubernetes/manifests". This can take up to 4m0s
[apiclient] All control plane components are healthy after 23.511845 seconds
[upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
[kubelet] Creating a ConfigMap "kubelet-config" in namespace kube-system with the configuration for the kubelets in the cluster
[upload-certs] Skipping phase. Please see --upload-certs
[mark-control-plane] Marking the node k8s-master01 as control-plane by adding the labels: [node-role.kubernetes.io/control-plane node.kubernetes.io/exclude-from-external-load-balancers]
[mark-control-plane] Marking the node k8s-master01 as control-plane by adding the taints [node-role.kubernetes.io/control-plane:NoSchedule]
[bootstrap-token] Using token: 8m1501.pnhgjv7cbs7lg5m8
[bootstrap-token] Configuring bootstrap tokens, cluster-info ConfigMap, RBAC Roles
[bootstrap-token] Configured RBAC rules to allow Node Bootstrap tokens to get nodes
[bootstrap-token] Configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials
[bootstrap-token] Configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token
[bootstrap-token] Configured RBAC rules to allow certificate rotation for all node client certificates in the cluster
[bootstrap-token] Creating the "cluster-info" ConfigMap in the "kube-public" namespace
[kubelet-finalize] Updating "/etc/kubernetes/kubelet.conf" to point to a rotatable kubelet client certificate and key
[addons] Applied essential addon: CoreDNS
[addons] Applied essential addon: kube-proxyYour Kubernetes control-plane has initialized successfully!To start using your cluster, you need to run the following as a regular user:mkdir -p $HOME/.kubesudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/configsudo chown $(id -u):$(id -g) $HOME/.kube/configAlternatively, if you are the root user, you can run:export KUBECONFIG=/etc/kubernetes/admin.confYou should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:https://kubernetes.io/docs/concepts/cluster-administration/addons/Then you can join any number of worker nodes by running the following on each as root:kubeadm join 192.168.91.100:6443 --token 8m1501.pnhgjv7cbs7lg5m8 \--discovery-token-ca-cert-hash sha256:bc2310202a958bb108066bb9b6f5927f82d66067e522742f642fadfa26ea2176
[root@k8s-master01 ~]#
k8s集群初始化终于成功了。
初始化过程说明:
- [preflight] kubeadm 执行初始化前的检查。
- [kubelet-start] 生成kubelet的配置文件”/var/lib/kubelet/config.yaml”
- [certificates] 生成相关的各种token和证书
- [kubeconfig] 生成 KubeConfig 文件,kubelet 需要这个文件与 Master 通信
- [control-plane] 安装 Master 组件,会从指定的 Registry 下载组件的 Docker 镜像。
- [bootstraptoken] 生成token记录下来,后边使用kubeadm join往集群中添加节点时会用到
- [addons] 安装附加组件 kube-proxy 和 kube-dns。 Kubernetes Master 初始化成功,提示如何配置常规用户使用kubectl访问集群。 提示如何安装 Pod 网络。 提示如何注册其他节点到 Cluster。
十七.master节点启动k8s集群;
1.master节点必要的环境配置;
# 普通用户操作
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
# root用户配置环境变量
export KUBECONFIG=/etc/kubernetes/admin.conf
# 使新配置环境变量生效
source /etc/profile

2.两个worker工作节点加入k8s集群;
worker02节点执行join到k8s集群的命令:
kubeadm join 192.168.91.100:6443 --token 8m1501.pnhgjv7cbs7lg5m8 \--discovery-token-ca-cert-hash sha256:bc2310202a958bb108066bb9b6f5927f82d66067e522742f642fadfa26ea2176

(1)所有woker节点(k8s-worker02和k8s-worker03)都要安装crictl;
k8s-worker02缺少crictl,执行安装命令:
yum install -y crictl


(2)所有worker节点都安装containerd;

# 全部worker节点查看containerd状态
systemctl status containerd

因为前面master节点安装过containerd,所以此处按照之前的方法,直接安装了。
①所有worker节点上传,解压“cri-containerd-1.6.22-linux-amd64.tar.gz”;
# 在根目录创建"/tools"目录
mkdir /tools

worker02和worker03要分别上传;




②两个worker节点都解压containerd压缩包到“/usr/local/bin/”;
tar -zxvf cri-containerd-1.6.22-linux-amd64.tar.gz -C /usr/local/bin/


③两个worker节点均拷贝二进制可执行文件到$PATH中;
ll /usr/local/bin

etc目录:主要为containerd服务管理配置文件及cni虚拟网卡配置文件;
opt目录:主要为gce环境中使用containerd配置文件及cni插件;
usr目录:主要为containerd运行时的二进制文件,包含runc;
# 在任意目录执行下面的命令,路径都是从根目录开始计算
cp /usr/local/bin/usr/local/bin/* /usr/local/bin/

④两个worker节点均赋予关键文件可执行权限,4=读,2=写,1=可执行,加一起就是他的权限。
正确命令如下:
chmod 0755 /usr/bin/containerd*
chmod 0755 /usr/bin/crictl
chmod 0755 /usr/local/bin/ctd-decoder
chmod 0755 /usr/bin/runc
chmod 0755 /usr/local/bin/ctr

⑤两个worker节点,把上面解压的这个文件"/usr/local/bin/etc/systemd/system/containerd.service",放到systemd的目录下:"/usr/lib/systemd/system/";

mv /usr/local/bin/etc/systemd/system/containerd.service /usr/lib/systemd/system/

cd /usr/lib/systemd/system/pwdll contain*

⑥两个worker节点均给containerd.service赋予权限;
chmod 0755 /usr/lib/systemd/system/containerd.service

⑦两个worker节点均给crictl配置参数;
如果你不想每次使用crictl都带一行类似下面这样的参数,
crictl --image-endpoint unix:///var/run/containerd/containerd.sock
那么你就执行下面的命令:
cat >>/etc/crictl.yaml <<EOF
runtime-endpoint: unix:///var/run/containerd/containerd.sock
image-endpoint: unix:///var/run/containerd/containerd.sock
timeout: 10
debug: false
EOF

⑧两个worker节点均启动containerd;
a.启动containerd命令:
systemctl daemon-reloadsystemctl enable containerdsystemctl start containerd
b.查询containerd运行状态:
systemctl status containerd

(3)两个worker节点再次加入k8s集群;
kubeadm join 192.168.91.100:6443 --token 8m1501.pnhgjv7cbs7lg5m8 \--discovery-token-ca-cert-hash sha256:bc2310202a958bb108066bb9b6f5927f82d66067e522742f642fadfa26ea2176

(4)在master节点查看k8s集群中的所有节点工作状态;
kubectl get nodes

3.在master节点使用k8s集群网络插件calico;
(1)master节点下载calico.yaml;
wget https://docs.projectcalico.org/v3.19/manifests/calico.yaml


(2)master节点修改配置calico.yaml;
vim calico.yaml

①.在xshell界面,“编辑”---->“查找”;

尝试后,发现在vim模式,这个搜索模式没法用。
②.在vim模式下,按下Esc键,确保处于正常模式,输入:/并加上要查找的关键字,然后按Enter键,比如":/CALICO_IPV4POOL_CIDR";


Vim会自动将光标移到第一次出现该关键字的位置;
按n键向前导航或N键向后查找;
按i进入可编辑模式,方向键+修改内容;
若要退出查找模式,可以按下Esc键返回正常模式。
本案例需要修改下面两行配置;
原来是:
# - name: CALICO_IPV4POOL_CIDR
# value: "192.168.0.0/16"
修改后:
- name: CALICO_IPV4POOL_CIDRvalue: "10.244.0.0/16"



(3)master节点执行命令:kubectl create -f calico.yaml
kubectl create -f calico.yaml
# 报错如下:
error: resource mapping not found for name: "calico-kube-controllers" namespace: "kube-system" from "calico.yaml": no matches for kind "PodDisruptionBudget" in version "policy/v1beta1"
ensure CRDs are installed first

4.根据网上资料,应该是k8s不支持当前calico版本的原因;
可以在在官网查看版本是否兼容。
Documentation archive | Calico DocumentationLinks to all versions of product documentation for Calico, Calico Enterprise, and Calico Cloud.
https://docs.tigera.io/archiveSystem requirements | Calico DocumentationReview requirements before installing Calico to ensure success.
https://docs.tigera.io/calico/latest/getting-started/kubernetes/requirements
(1)master节点下载calico.yaml;(v3.26)(v3.27)均无法下载,不可用。
wget https://docs.projectcalico.org/v3.26/manifests/calico.yaml

wget https://docs.projectcalico.org/v3.27/manifests/calico.yaml

calico v3.25版本匹配,也可以下载,可使用;
wget https://docs.projectcalico.org/v3.25/manifests/calico.yaml


(2)master节点修改配置calico.yaml;
vim calico.yaml

(3)master节点执行命令:kubectl create -f calico.yaml
kubectl create -f calico.yaml

更新现有资源:如果你要更新已经存在的资源,可以使用 kubectl apply 命令。确保将更新的配置保存到 YAML 文件中,并使用以下命令执行更新:
kubectl apply -f calico.yaml

5.在master节点查看多个节点运行状态"kubectl get pods -n kube-system";
kubectl get pods -n kube-system

kubectl get nodes

6.worker节点join到master节点;
kubeadm join 192.168.91.100:6443 --token 8m1501.pnhgjv7cbs7lg5m8 \--discovery-token-ca-cert-hash sha256:bc2310202a958bb108066bb9b6f5927f82d66067e522742f642fadfa26ea2176



7.worker节点"NotReady"的问题;
(1)在master节点执行"kubectl get nodes";
[root@k8s-master01 ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master01 Ready control-plane 2d6h v1.25.3
k8s-worker02 NotReady <none> 2d4h v1.25.3
k8s-worker03 NotReady <none> 2d4h v1.25.3
参考calico官方安装文档;
Quickstart for Calico on Kubernetes | Calico DocumentationInstall Calico on a single-host Kubernetes cluster for testing or development in under 15 minutes.
https://docs.tigera.io/calico/3.25/getting-started/kubernetes/quickstart
(2)所有主机重置k8s;
kubeadm reset

(3)master节点重新初始化;
# master节点执行
kubeadm init --node-name=k8s-master01 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.25.16 \
--apiserver-advertise-address=192.168.91.100 \
--pod-network-cidr=10.244.0.0/16 \
--service-cidr=10.96.0.0/12

[root@k8s-master01 ~]# kubeadm init --node-name=k8s-master01 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.25.16 \
--apiserver-advertise-address=192.168.91.100 \
--pod-network-cidr=10.244.0.0/16 \
--service-cidr=10.96.0.0/12
[init] Using Kubernetes version: v1.25.16
[preflight] Running pre-flight checks
[preflight] Pulling images required for setting up a Kubernetes cluster
[preflight] This might take a minute or two, depending on the speed of your internet connection
[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'
[certs] Using certificateDir folder "/etc/kubernetes/pki"
[certs] Generating "ca" certificate and key
[certs] Generating "apiserver" certificate and key
[certs] apiserver serving cert is signed for DNS names [k8s-master01 kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 192.168.91.100]
[certs] Generating "apiserver-kubelet-client" certificate and key
[certs] Generating "front-proxy-ca" certificate and key
[certs] Generating "front-proxy-client" certificate and key
[certs] Generating "etcd/ca" certificate and key
[certs] Generating "etcd/server" certificate and key
[certs] etcd/server serving cert is signed for DNS names [k8s-master01 localhost] and IPs [192.168.91.100 127.0.0.1 ::1]
[certs] Generating "etcd/peer" certificate and key
[certs] etcd/peer serving cert is signed for DNS names [k8s-master01 localhost] and IPs [192.168.91.100 127.0.0.1 ::1]
[certs] Generating "etcd/healthcheck-client" certificate and key
[certs] Generating "apiserver-etcd-client" certificate and key
[certs] Generating "sa" key and public key
[kubeconfig] Using kubeconfig folder "/etc/kubernetes"
[kubeconfig] Writing "admin.conf" kubeconfig file
[kubeconfig] Writing "kubelet.conf" kubeconfig file
[kubeconfig] Writing "controller-manager.conf" kubeconfig file
[kubeconfig] Writing "scheduler.conf" kubeconfig file
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Starting the kubelet
[control-plane] Using manifest folder "/etc/kubernetes/manifests"
[control-plane] Creating static Pod manifest for "kube-apiserver"
[control-plane] Creating static Pod manifest for "kube-controller-manager"
[control-plane] Creating static Pod manifest for "kube-scheduler"
[etcd] Creating static Pod manifest for local etcd in "/etc/kubernetes/manifests"
[wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory "/etc/kubernetes/manifests". This can take up to 4m0s
[apiclient] All control plane components are healthy after 7.505709 seconds
[upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
[kubelet] Creating a ConfigMap "kubelet-config" in namespace kube-system with the configuration for the kubelets in the cluster
[upload-certs] Skipping phase. Please see --upload-certs
[mark-control-plane] Marking the node k8s-master01 as control-plane by adding the labels: [node-role.kubernetes.io/control-plane node.kubernetes.io/exclude-from-external-load-balancers]
[mark-control-plane] Marking the node k8s-master01 as control-plane by adding the taints [node-role.kubernetes.io/control-plane:NoSchedule]
[bootstrap-token] Using token: zxa6xc.q8wtvtez4zkhmusi
[bootstrap-token] Configuring bootstrap tokens, cluster-info ConfigMap, RBAC Roles
[bootstrap-token] Configured RBAC rules to allow Node Bootstrap tokens to get nodes
[bootstrap-token] Configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials
[bootstrap-token] Configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token
[bootstrap-token] Configured RBAC rules to allow certificate rotation for all node client certificates in the cluster
[bootstrap-token] Creating the "cluster-info" ConfigMap in the "kube-public" namespace
[kubelet-finalize] Updating "/etc/kubernetes/kubelet.conf" to point to a rotatable kubelet client certificate and key
[addons] Applied essential addon: CoreDNS
[addons] Applied essential addon: kube-proxyYour Kubernetes control-plane has initialized successfully!To start using your cluster, you need to run the following as a regular user:mkdir -p $HOME/.kubesudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/configsudo chown $(id -u):$(id -g) $HOME/.kube/configAlternatively, if you are the root user, you can run:export KUBECONFIG=/etc/kubernetes/admin.confYou should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:https://kubernetes.io/docs/concepts/cluster-administration/addons/Then you can join any number of worker nodes by running the following on each as root:kubeadm join 192.168.91.100:6443 --token zxa6xc.q8wtvtez4zkhmusi \--discovery-token-ca-cert-hash sha256:63826f6a9e565823d6c455c281914a58b24eaca7a04b59af5b17fdd13b976633
[root@k8s-master01 ~]#
(4)master节点执行下面命令;
# 普通用户操作
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

# root用户配置环境变量
export KUBECONFIG=/etc/kubernetes/admin.conf
# 使新配置环境变量生效
source /etc/profile

(5)两个worker节点join到master节点;
kubeadm join 192.168.91.100:6443 --token zxa6xc.q8wtvtez4zkhmusi \--discovery-token-ca-cert-hash sha256:63826f6a9e565823d6c455c281914a58b24eaca7a04b59af5b17fdd13b976633


在master节点执行"kubectl get nodes";

(6)master节点安装calico v3.25.2;
Quickstart for Calico on Kubernetes | Calico DocumentationInstall Calico on a single-host Kubernetes cluster for testing or development in under 15 minutes.
https://docs.tigera.io/calico/3.25/getting-started/kubernetes/quickstart
①执行下面命令,生成tigera-operator.yaml;
kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.25.2/manifests/tigera-operator.yaml
Quickstart for Calico on Kubernetes | Calico DocumentationInstall Calico on a single-host Kubernetes cluster for testing or development in under 15 minutes.
https://docs.tigera.io/calico/3.25/getting-started/kubernetes/quickstart

②重点注意下面命令,与calico官方文档执行有些不同;
wget https://raw.githubusercontent.com/projectcalico/calico/v3.25.2/manifests/custom-resources.yaml

③编辑custom-resources.yaml文件内容;
vim custom-resources.yaml

显示行号:进入vim模式,按"Esc",再按":",输入"set nu",再点"Enter"。

点"i"进入可编辑模式,修改cidr值,再依次点"Esc"、":wq",点击"Enter"保存退出。

④执行编辑后的custom-resources.yaml文件;
kubectl create -f custom-resources.yaml
kubectl get ns


⑤删除已经存在的"custom-resources.yaml",消除上面的错误;
kubectl delete -f https://raw.githubusercontent.com/projectcalico/calico/v3.25.2/manifests/custom-resources.yaml
重新执行命令:
kubectl create -f custom-resources.yaml
kubectl get ns

(7)kubernetes YUM源准备,所有集群主机均需操作;
# 谷歌YUM源
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpghttps://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOFyum check-update #清除yum缓存
此处使用阿里云,修改下边的"gpgcheck=0, repo_gpgcheck=0"跳过验证;
# 阿里云:
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[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
EOFyum check-update #清除yum缓存
# 华为云:具体见:https://www.huaweicloud.com/zhishi/Kubernetes.html
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://repo.huaweicloud.com/kubernetes/yum/repos/kubernetes-el7-$basearch
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://repo.huaweicloud.com/kubernetes/yum/doc/yum-key.gpg https://repo.huaweicloud.com/kubernetes/yum/doc/rpm-package-key.gpg
EOFyum check-update #清除yum缓存




master节点执行“yum check-update #清除yum缓存”报错;

# 执行完成之后, 所有节点均需要刷新yum源
yum repolist



(8)所有主机执行"vim /etc/sysconfig/kubelet";
vim /etc/sysconfig/kubelet
所有主机的内容设置为:
KUBELET_EXTRA_ARGS="--cgroup-driver=systemd"



所有主机设置kubelet开机自启;
systemctl enable kubelet

(9)三台主机的kubelet运行中报错;
systemctl status kubelet



(10)master节点删除calico v3.25.2,安装calico v3.24.6;
直接安装calico v3.24.6会提示一堆文件已经存在,所以必须先删除v3.25.2版本,再安装v3.24.6;

# 卸载calico v3.25.2 的custom-resources.yaml
kubectl delete -f https://raw.githubusercontent.com/projectcalico/calico/v3.25.2/manifests/custom-resources.yaml# 卸载calico v3.25.2 的tigera-operator.yaml
kubectl delete -f https://raw.githubusercontent.com/projectcalico/calico/v3.25.2/manifests/tigera-operator.yaml
如果删除失败,有可能是网络问题,重新删除即可。

安装calico v3.24.6;
# 下载 tigera-operator.yaml
wget https://raw.githubusercontent.com/projectcalico/calico/v3.24.6/manifests/tigera-operator.yaml# 安装 tigera-operator.yaml
kubectl create -f tigera-operator.yaml


# 下载calico v3.24.6 的custom-resources.yaml
wget https://raw.githubusercontent.com/projectcalico/calico/v3.24.6/manifests/custom-resources.yaml# 安装calico v3.24.6 的custom-resources.yaml
kubectl create -f custom-resources.yaml

(11)master节点执行 vim /etc/containerd/config.toml ,修改sandbox_iamge的行如下所示:
sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.8"
下图中只改了版本号;(感觉两个地址差不多)


改完之后,执行:systemctl restart containerd 重启containerd;
systemctl restart containerd


(12)"kubectl get nodes"命令,所有节点状态为"NotReady"的解决方法;
kubectl get nodes
问题截图如下:

# 重启服务,查看状态
systemctl restart --now kubelet ; systemctl status kubelet.service --now# 查看kubelet日志
journalctl -f -u kubelet

在NotReady的节点,执行下面命令,状态就可变为Ready;
# 创建目录
mkdir -p /etc/cni/net.d# 保存文件,写入内容
cat > /etc/cni/net.d/10-flannel.conflist << EOF
{"name": "cbr0","plugins": [{"type": "flannel","delegate": {"hairpinMode": true,"isDefaultGateway": true}},{"type": "portmap","capabilities": {"portMappings": true}}]
}
EOF
# 重启kubelet
systemctl restart kubelet# 查看节点状态
kubectl get nodes




(13)master节点重新安装calico v3.25;
先卸载上面用另一种方式安装的calico v3.24.6;
# 卸载 calico v3.24.6
kubectl delete -f https://raw.githubusercontent.com/projectcalico/calico/v3.24.6/manifests/custom-resources.yaml
kubectl delete -f https://raw.githubusercontent.com/projectcalico/calico/v3.24.6/manifests/tigera-operator.yaml

# 下载calico.yaml v3.25
wget https://docs.tigera.io/archive/v3.25/manifests/calico.yaml
# 编辑
vim calico.yaml

# 安装calico.yaml v3.25
kubectl create -f calico.yaml# 查看pods
kubectl get pods -n kube-system

相关文章:
OpenEular23.09(欧拉)操作系统为企业搭建独立的K8S集群环境,详细流程+截图
一.环境; win10,vmware16 pro,openeular23.09,linux内核 6.4.0-10.1.0.20.oe2309.x86_64, docker-engine 2:18.09.0-328,kubernetes 1.25.3,containerd 1.6.22,calico v3.25 集群…...
学生成绩管理系统半成品
C语言的老师在给我们讲指针的时候,讲的并不深入,她用了一个学生成绩管理系统来引入指针这个东西并给我们讲解,但我觉得她的管理系统功能有一些不足,并且不是很美观,所以说心血来潮,自己也动手写了一个学生成…...
国家信息安全水平等级考试NISP二级题目卷⑤(包含答案)
国家信息安全水平等级考试NISP二级题目卷(五) 国家信息安全水平等级考试NISP二级题目卷(五)需要报考咨询可以私信博主! 前言: 国家信息安全水平考试(NISP)二级,被称为校园版”CISP”,由中国信息…...
4.快速实现增删改查,模糊查询功能
打开springboot项目,在com.example下建包common,在common下新建Result.java 4.1封装统一的返回数据结构 1.在Result.java中编写如下代码: private static final String *SUCCESS*"0"; private static final String *ERROR*"-1"; p…...
【Redux】自己动手实现redux和react-redux
1. React提供context的作用 在class组件的世界里,如果后代组件共享某些状态,比如主题色、语言键,则需要将这些状态提升到根组件,以props的方式从根组件向后代组件一层一层传递,这样则需要在每层写props.someData&#…...
代码随想录算法训练营day6|242.有效的字母异位词、349.两个数组的交集、202.快乐数
哈希表理论基础 建议:大家要了解哈希表的内部实现原理,哈希函数,哈希碰撞,以及常见哈希表的区别,数组,set 和map。 什么时候想到用哈希法,当我们遇到了要快速判断一个元素是否出现集合里的时…...
2024.1.4每日一题
LeetCode每日一题 2397.被列覆盖的最多行数 2397. 被列覆盖的最多行数 - 力扣(LeetCode) 题目描述 给你一个下标从 0 开始、大小为 m x n 的二进制矩阵 matrix ;另给你一个整数 numSelect,表示你必须从 matrix 中选择的 不同 …...
C++协程和线程的区别?详细介绍一下C++协程
C协程和线程的区别 线程是操作系统级别的资源,由操作系统负责调度和切换,每个线程都有自己的堆栈和执行上下文。线程之间的切换需要保存和恢复线程的执行上下文,这个过程有一定的开销。协程是用户态的轻量级线程,协程的调度完全由…...
数字信号处理期末复习——计算大题(一)
个人名片: 🦁作者简介:一名喜欢分享和记录学习的在校大学生 🐯个人主页:妄北y 🐧个人QQ:2061314755 🐻个人邮箱:2061314755qq.com 🦉个人WeChat:V…...
matlab数值计算函数--ode45
当难以求得微分方程的解析解时,可以求其数值解,Matlab中求微分方程数值解的函数有七个:ode45,ode23,ode113,ode15s,ode23s,ode23t,ode23tb。本文讲解ode45,其…...
Vue3地图选点组件
Vue3地图选点组件 <template><div style"width: 100%; height: 500px"><div class"search-container"><el-autocompletev-model"suggestionKeyWord"class"search-container__input"clearable:fetch-suggestion…...
JS之注册事件兼容性解决方案
本章介绍注册事件兼容性的解决方案 废话不多说,直接上代码: function addEventListener(element, eventName, fn) {//判断当前浏览器是否支持 addEventListener 方法if (element.addEventListener) {element.addEventListener(eventName, fn); // 第三个…...
C#中使用as关键字将对象转换为指定类型
目录 一、定义 二、示例 三、生成 使用as关键字可以将对象转换为指定类型,与is关键字不同,is关键字用于检查对象是否与给定类型兼容,如果兼容则返回true,如果不兼容则返回false。而as关键字会直接进行类型转换,如果…...
【Spring实战】21 Spring Data REST 常用功能详细介绍
文章目录 1. 资源导出(Resource Exporting)2. 查询方法(Query Methods)3. 分页和排序(Pagination and Sorting)4. 关联关系(Associations)5. 事件(Events)6. …...
05-微服务-RabbitMQ-概述
RabbitMQ 1.初识MQ 1.1.同步和异步通讯 微服务间通讯有同步和异步两种方式: 同步通讯:就像打电话,需要实时响应。 异步通讯:就像发邮件,不需要马上回复。 两种方式各有优劣,打电话可以立即得到响应&am…...
jmeter参数化的三种方式
1.用户定义变量 使用变量: ${变量名} 这个变量是全局变量,也就是在下面子节点中都可以使用; 使用场景:两个账号分别有不同的权限,A经办,B审核。等。。。 2.CSV数据文件设置 3.函数...
java基础之Java8新特性-Lambda
目录 什么是Lambda表达式 Lambda表达式规范 基本语法 参数列表 函数体 注意事项 如何定义函数接口 1.保证接口中只能有一个抽象方法 2.使用FunctionalInterface注解标记该接口为函数接口 使用Lambda调用无参函数 使用Lambda调用有参函数 使用Lambda的精简写法 使用…...
入门使用mybatis-plus
第一步:pom文件带入依赖 <dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.5.1</version> </dependency> 第二步:创建实体对象 TableName(&…...
ubuntu安装和配置ssh教程
一、前言 ssh服务类似于windows的远程桌面服务,可以实现对linux系统的远程管理,ssh默认端口为22端口。后面博主进行操作以ubuntu2020操作系统为例进行操作。 二、安装ssh服务 Ubuntu 2020 默认不安装 SSH 服务。它只安装了 SSH 客户端,可以用于连接到其他计算机上的 SSH 服…...
每天刷两道题——第六天
1.1字母异位词分组 给你一个字符串数组,将字母异位词组合在一起。可以按任意顺序返回结果列表。字母异位词指的是由重新排列源单词的所有字母得到的一个新单词。 输入: strs [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”] 输出: [[“bat”],[“nat”,…...
Spark 之 入门讲解详细版(1)
1、简介 1.1 Spark简介 Spark是加州大学伯克利分校AMP实验室(Algorithms, Machines, and People Lab)开发通用内存并行计算框架。Spark在2013年6月进入Apache成为孵化项目,8个月后成为Apache顶级项目,速度之快足见过人之处&…...
大数据零基础学习day1之环境准备和大数据初步理解
学习大数据会使用到多台Linux服务器。 一、环境准备 1、VMware 基于VMware构建Linux虚拟机 是大数据从业者或者IT从业者的必备技能之一也是成本低廉的方案 所以VMware虚拟机方案是必须要学习的。 (1)设置网关 打开VMware虚拟机,点击编辑…...
Keil 中设置 STM32 Flash 和 RAM 地址详解
文章目录 Keil 中设置 STM32 Flash 和 RAM 地址详解一、Flash 和 RAM 配置界面(Target 选项卡)1. IROM1(用于配置 Flash)2. IRAM1(用于配置 RAM)二、链接器设置界面(Linker 选项卡)1. 勾选“Use Memory Layout from Target Dialog”2. 查看链接器参数(如果没有勾选上面…...
uniapp微信小程序视频实时流+pc端预览方案
方案类型技术实现是否免费优点缺点适用场景延迟范围开发复杂度WebSocket图片帧定时拍照Base64传输✅ 完全免费无需服务器 纯前端实现高延迟高流量 帧率极低个人demo测试 超低频监控500ms-2s⭐⭐RTMP推流TRTC/即构SDK推流❌ 付费方案 (部分有免费额度&#x…...
用docker来安装部署freeswitch记录
今天刚才测试一个callcenter的项目,所以尝试安装freeswitch 1、使用轩辕镜像 - 中国开发者首选的专业 Docker 镜像加速服务平台 编辑下面/etc/docker/daemon.json文件为 {"registry-mirrors": ["https://docker.xuanyuan.me"] }同时可以进入轩…...
LeetCode - 199. 二叉树的右视图
题目 199. 二叉树的右视图 - 力扣(LeetCode) 思路 右视图是指从树的右侧看,对于每一层,只能看到该层最右边的节点。实现思路是: 使用深度优先搜索(DFS)按照"根-右-左"的顺序遍历树记录每个节点的深度对于…...
NPOI操作EXCEL文件 ——CAD C# 二次开发
缺点:dll.版本容易加载错误。CAD加载插件时,没有加载所有类库。插件运行过程中用到某个类库,会从CAD的安装目录找,找不到就报错了。 【方案2】让CAD在加载过程中把类库加载到内存 【方案3】是发现缺少了哪个库,就用插件程序加载进…...
毫米波雷达基础理论(3D+4D)
3D、4D毫米波雷达基础知识及厂商选型 PreView : https://mp.weixin.qq.com/s/bQkju4r6med7I3TBGJI_bQ 1. FMCW毫米波雷达基础知识 主要参考博文: 一文入门汽车毫米波雷达基本原理 :https://mp.weixin.qq.com/s/_EN7A5lKcz2Eh8dLnjE19w 毫米波雷达基础…...
MySQL:分区的基本使用
目录 一、什么是分区二、有什么作用三、分类四、创建分区五、删除分区 一、什么是分区 MySQL 分区(Partitioning)是一种将单张表的数据逻辑上拆分成多个物理部分的技术。这些物理部分(分区)可以独立存储、管理和优化,…...
MyBatis中关于缓存的理解
MyBatis缓存 MyBatis系统当中默认定义两级缓存:一级缓存、二级缓存 默认情况下,只有一级缓存开启(sqlSession级别的缓存)二级缓存需要手动开启配置,需要局域namespace级别的缓存 一级缓存(本地缓存&#…...
