Docker容器化K8s集群部署教程(一键部署sheel脚本)

news2025/5/24 16:09:10

本文通过脚本,可以快速地部署和配置Kubernetes环境,省去了各插件手动部署、配置的繁琐过程。

先看最终结果:

[root@localhost home]# kubectl get node
NAME        STATUS   ROLES           AGE    VERSION
k8smaster   Ready    control-plane   113m   v1.28.2
k8snode1    Ready    <none>          104m   v1.28.2
k8snode2    Ready    <none>          96m    v1.28.2

K8s集群部署

1. 环境准备

1.1. 准备资源

3 台服务器: Centos 7.6 系统,内核版本:3.10.0-1160.71.1.el7.x86_64,在每个节点上添加 hosts 信息(脚本中会自动添加):

IP

备注

Hosts

10.8.42.15

master

k8smaster

10.8.42.16

node1

k8snode1

10.8.42.17

node2

k8snode2

1.2. 准备网络

如果服务器已经可以上网,可忽略此步骤。

检查DNS:cat /etc/resolv.conf

若为空,则配置vi /etc/resolv.conf

插入内容:nameserver 61.139.2.69 (具体根据公司情况添加)

1.3. 准备工具

安装rz/sz命令,方便上传下载文件(可选)。

yum -y install lrzsz

1.4. 准备安装包、脚本、配置文件

  脚本/安装包/配置下载地址:https://download.csdn.net/download/yqwang75457/88816709

💡下载后不要急着直接安装,建议先看一下install-k8s.sh、install-k8s-common.sh、kubeadm.yaml这3个文件,脚本注释相对完整,先了解一下安装的大体流程。且其中2个文件需要做一些小的修改的(个人觉得vi不好用,因此建议先在本地把文件配置修改正确,再上传到服务器,具体修改内容,详解下文1.5

1.5. 相关文件说明及脚本修改

大致了解下载下来的文件,并根据服务器资源、安装版本等情况,可能需要修改脚本部分内容

1.5.1. 关于安装包cri-dockerd-0.3.9-3.el7.x86_64.rpm

本想着在安装脚本中下载并使用这玩意儿的,可是这个github老是访问不了!访问不了!访问不了!访问不了!因此只能用手动下载了。

版本替换(可选):

可选择合适版本下载进行替换,替换后记得修改install-k8s-common.sh中cri_dockerd_version变量值,下载地址(GitHub) Releases · Mirantis/cri-dockerd · GitHub

1.5.2. 修改install-k8s-common.sh文件

主要修改集群节点规划、软件版本信息(根据实际情况修改)。

# 指定k8s主节点ip(改!)
k8s_master_ip = "10.8.42.15"

# host配置(按集群规划配置)(改!)
k8snodes[0]='10.8.42.15 k8smaster';
k8snodes[1]='10.8.42.16 k8snode1';
k8snodes[2]='10.8.42.17 k8snode2'; 

# 容器运行时版本
docker_version="24.0.7"
cri_dockerd_version="0.3.9"

# Docker镜像加速器(用公司账号去阿里云获取!)(改!)
# 详见https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors	
docker_registry_mirrors="https://8v0yq4vh.mirror.aliyuncs.com"

# k8s版本
k8s_version="v1.28.2"
k8s_kubeadm_version="1.28.2"
k8s_kubelet_version="1.28.2"
k8s_kubectl_version="1.28.2"
1.5.3. 修改kubeadm.yaml文件

必要修改部分!!!

# 修改1.
localAPIEndpoint下
  advertiseAddress: 10.8.42.15 #改!Master的ip地址

# 修改2.
nodeRegistration下
  criSocket: unix:///var/run/cri-dockerd.sock #改!
  imagePullPolicy: IfNotPresent 
  name: k8smaster #改!(主节点域名)

# 修改3.  
imageRepository: registry.aliyuncs.com/google_containers  #改!
kubernetesVersion: 1.28.2 #改!k8s版本
# 修改4.
networking下
networking:
  dnsDomain: cluster.local
  serviceSubnet: 10.96.0.0/12
  podSubnet: 10.244.0.0/16 #添加此行!pod子网地址
scheduler: {}

# 修改5.
#↓↓↓要添加的ipvs模式!
---
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
mode: ipvs
---
#↑↑↑要添加的ipvs模式!

等安装完成后,可以用这个命令重新生成此配置文件,看看默认的是什么样子:

kubeadm config print init-defaults --component-configs KubeletConfiguration > kubeadm_default.yaml
1.5.4. 关于网络插件kube-flannel.yml

上文下载文件中包含kube-flannel.yml,也可以下载最新的进行替换:https://github.com/flannel-io/flannel/releases/tag/v0.22.0

2. 安装

终于开始了~终于开始了~终于开始了~

2.1. 上传安装包

完成修改后,用rz命令或ftp工具将这些文件上传到各服务器的/home目录

1.安装包cri-dockerd-0.3.9-3.el7.x86_64.rpm;

2.安装脚本install-k8s-common.sh、install-k8s.sh;

3.卸载脚本uninstall-k8s.sh;

4.初始化配置文件kubeadm.yaml;

5.网络插件配置文件kube-flannel.yml;

并执行脚本授权:chmod +x *.sh

chmod +x *.sh

​​

2.2. Master、Node节点均依次执行安装脚本

./install-k8s.sh

💡安装过程中有2个确认逻辑:

1.以上↑↑↑↑↑↑↑主机配置hosts是否正确?默认为 no. Enter [yes/no]:yes

2.[reset] Are you sure you want to proceed? [y/N]: y

等待安装完成即可!!!

2.3. Master、Node安装日志

如果安装失败,可以对比我的安装日志(我安装了不下于10次,都是成功的)。

2.3.1. Master安装日志

439行Your Kubernetes control-plane has initialized successfully!显示集群搭建完成;

457行

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 10.8.42.15:6443 --token abcdef.0123456789abcdef \

--discovery-token-ca-cert-hash sha256:dcb3a92796f3e28eeea7fa4200568da048a20e37f2ccdbb7953db6ac0ecd8804

💡注意这里的token在node加入集群需要。如果忘记保存或token已过期?继续查看下文《节点join集群》。

完整日志如下:

[root@localhost home]# ./install-k8s.sh 
Hello, Let's Go!
[20240206 01:25:52] [Info] #########################################################################################
[20240206 01:25:52] [Info] ################################# 初始化服务器环境设置... ################################
[20240206 01:25:52] [Info] #########################################################################################
[20240206 01:25:52] [Info] 1.关闭用防火墙
[20240206 01:25:52] [Info] 2.配置域名解析
[20240206 01:25:52] [Info] 确认hosts域名配置--

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6 
10.8.42.15 k8smaster
10.8.42.16 k8snode1
10.8.42.17 k8snode2
以上↑↑↑↑↑↑↑主机配置hosts是否正确?默认为 no. Enter [yes/no]:yes
[20240206 01:25:52] [Info] 确认已配置hosts
[20240206 01:25:52] [Info] 3.必须关闭swap分区
[20240206 01:25:52] [Info] 4.临时关闭selinux防火墙
[20240206 01:25:52] [Info] 5.配置服务器时间保持一致[工具:chrony]
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.ustc.edu.cn
软件包 chrony-3.4-1.el7.x86_64 已安装并且是最新版本
无须任何处理
210 Number of sources = 4
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^- 81.16.177.123                 2   6   177    23  -8195us[-8195us] +/-  140ms
^- stratum2-1.ntp.mow01.ru.>     2   7     5    80    +20ms[  +20ms] +/-  101ms
^* time.neu.edu.cn               1   6   177    24    -75us[ -376us] +/-   23ms
^? ntp5.flashdance.cx            0   8     0     -     +0ns[   +0ns] +/-    0ns
2024年 02月 06日 星期二 01:25:54 EST
[20240206 01:25:52] [Info] 6.添加网桥过滤和地址转发功能
[20240206 01:25:52] [Info] 6.1.添加网桥过滤和地址转发功能:添加配置
overlay
br_netfilter
net.bridge.bridge-nf-call-ip6tables=1
net.bridge.bridge-nf-call-iptables=1
net.ipv4.ip_forward=1
# 下面的内核参数可以解决ipvs模式下长连接空闲超时的问题
net.ipv4.tcp_keepalive_intvl=30
net.ipv4.tcp_keepalive_probes=10
net.ipv4.tcp_keepalive_time=600
vm.swappiness=0
[20240206 01:25:52] [Info] 6.2.添加网桥过滤和地址转发功能:重新加载配置
* Applying /usr/lib/sysctl.d/00-system.conf ...
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0
* Applying /usr/lib/sysctl.d/10-default-yama-scope.conf ...
kernel.yama.ptrace_scope = 0
* Applying /usr/lib/sysctl.d/50-default.conf ...
kernel.sysrq = 16
kernel.core_uses_pid = 1
kernel.kptr_restrict = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.promote_secondaries = 1
net.ipv4.conf.all.promote_secondaries = 1
fs.protected_hardlinks = 1
fs.protected_symlinks = 1
* Applying /etc/sysctl.d/99-sysctl.conf ...
* Applying /etc/sysctl.d/k8s.conf ...
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
net.ipv4.tcp_keepalive_intvl = 30
net.ipv4.tcp_keepalive_probes = 10
net.ipv4.tcp_keepalive_time = 600
vm.swappiness = 0
* Applying /etc/sysctl.conf ...
[20240206 01:25:52] [Info] 6.3.添加网桥过滤和地址转发功能:加载网桥过滤器模块
[20240206 01:25:52] [Info] 6.4.添加网桥过滤和地址转发功能:确认 br_netfilter 和 overlay 模块被加载
br_netfilter           22256  0 
bridge                151336  1 br_netfilter
overlay                91659  0 
[20240206 01:25:52] [Info] 6.5.添加网桥过滤和地址转发功能:确认系统变量在你的 sysctl 配置中被设置为 1
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1
[20240206 01:25:52] [Info] 7.配置ipvs功能
[20240206 01:25:52] [Info] 7.1.配置ipvs功能:安装ipset和ipvsadm
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.ustc.edu.cn
软件包 ipvsadm-1.27-8.el7.x86_64 已安装并且是最新版本
软件包 ipset-7.1-1.el7.x86_64 已安装并且是最新版本
软件包 sysstat-10.1.5-20.el7_9.x86_64 已安装并且是最新版本
软件包 conntrack-tools-1.4.4-7.el7.x86_64 已安装并且是最新版本
无须任何处理
[20240206 01:25:52] [Info] 7.2.配置ipvs功能:添加需要加载的模块写入脚本文件
[20240206 01:25:52] [Info] 7.3.配置ipvs功能:重启服务
[20240206 01:25:52] [Info] 7.4.配置ipvs功能:查看对应的模块是否加载成功
nf_conntrack_ipv6      18935  3 
nf_defrag_ipv6         35104  1 nf_conntrack_ipv6
nf_conntrack_netlink    36396  0 
nf_conntrack_ipv4      15053  5 
nf_defrag_ipv4         12729  1 nf_conntrack_ipv4
ip_vs_sh               12688  0 
ip_vs_wrr              12697  0 
ip_vs_rr               12600  4 
ip_vs                 145458  10 ip_vs_rr,ip_vs_sh,ip_vs_wrr
nf_conntrack          139264  10 ip_vs,nf_nat,nf_nat_ipv4,nf_nat_ipv6,xt_conntrack,nf_nat_masquerade_ipv4,nf_nat_masquerade_ipv6,nf_conntrack_netlink,nf_conntrack_ipv4,nf_conntrack_ipv6
nfnetlink              14519  3 nf_tables,ip_set,nf_conntrack_netlink
libcrc32c              12644  4 xfs,ip_vs,nf_nat,nf_conntrack
[20240206 01:25:52] [Info] #########################################################################################
[20240206 01:25:52] [Info] ################################# Start Install Docker... ###############################
[20240206 01:25:52] [Info] #########################################################################################
[20240206 01:25:52] [Info] 准备安装Docker,版本:24.0.7
[20240206 01:25:52] [Info] 安装Docker:1.yum-utils软件用于提供yum-config-manager程序
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.ustc.edu.cn
软件包 yum-utils-1.1.31-54.el7_8.noarch 已安装并且是最新版本
无须任何处理
[20240206 01:25:52] [Info] 安装Docker:2.使用yum-config-manager创建docker阿里存储库
已加载插件:fastestmirror
adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.ustc.edu.cn
base                                                                                                                                                                                                                            | 3.6 kB  00:00:00     
docker-ce-stable                                                                                                                                                                                                                | 3.5 kB  00:00:00     
extras                                                                                                                                                                                                                          | 2.9 kB  00:00:00     
kubernetes                                                                                                                                                                                                                      | 1.4 kB  00:00:00     
updates                                                                                                                                                                                                                         | 2.9 kB  00:00:00     
元数据缓存已建立
[20240206 01:25:52] [Info] 安装Docker:3.配置Docker镜像加速器/修改cgroup方式
[20240206 01:25:52] [Info] 安装Docker:4.开始执行安装
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.ustc.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 containerd.io.x86_64.0.1.6.28-3.1.el7 将被 安装
---> 软件包 docker-buildx-plugin.x86_64.0.0.12.1-1.el7 将被 安装
---> 软件包 docker-ce.x86_64.3.24.0.7-1.el7 将被 安装
--> 正在处理依赖关系 docker-ce-rootless-extras,它被软件包 3:docker-ce-24.0.7-1.el7.x86_64 需要
---> 软件包 docker-ce-cli.x86_64.1.24.0.7-1.el7 将被 安装
---> 软件包 docker-compose-plugin.x86_64.0.2.24.5-1.el7 将被 安装
--> 正在检查事务
---> 软件包 docker-ce-rootless-extras.x86_64.0.25.0.2-1.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

=======================================================================================================================================================================================================================================================
 Package                                                              架构                                              版本                                                         源                                                           大小
=======================================================================================================================================================================================================================================================
正在安装:
 containerd.io                                                        x86_64                                            1.6.28-3.1.el7                                               docker-ce-stable                                             35 M
 docker-buildx-plugin                                                 x86_64                                            0.12.1-1.el7                                                 docker-ce-stable                                             13 M
 docker-ce                                                            x86_64                                            3:24.0.7-1.el7                                               docker-ce-stable                                             24 M
 docker-ce-cli                                                        x86_64                                            1:24.0.7-1.el7                                               docker-ce-stable                                             13 M
 docker-compose-plugin                                                x86_64                                            2.24.5-1.el7                                                 docker-ce-stable                                             13 M
为依赖而安装:
 docker-ce-rootless-extras                                            x86_64                                            25.0.2-1.el7                                                 docker-ce-stable                                            9.4 M

事务概要
=======================================================================================================================================================================================================================================================
安装  5 软件包 (+1 依赖软件包)

总下载量:108 M
安装大小:380 M
Downloading packages:
(1/6): docker-buildx-plugin-0.12.1-1.el7.x86_64.rpm                                                                                                                                                                             |  13 MB  00:00:06     
(2/6): docker-ce-24.0.7-1.el7.x86_64.rpm                                                                                                                                                                                        |  24 MB  00:00:12     
(3/6): containerd.io-1.6.28-3.1.el7.x86_64.rpm                                                                                                                                                                                  |  35 MB  00:00:20     
(4/6): docker-ce-rootless-extras-25.0.2-1.el7.x86_64.rpm                                                                                                                                                                        | 9.4 MB  00:00:05     
(5/6): docker-ce-cli-24.0.7-1.el7.x86_64.rpm                                                                                                                                                                                    |  13 MB  00:00:07     
(6/6): docker-compose-plugin-2.24.5-1.el7.x86_64.rpm                                                                                                                                                                            |  13 MB  00:00:08     
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                                                                                                                                   3.1 MB/s | 108 MB  00:00:34     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : containerd.io-1.6.28-3.1.el7.x86_64                                                                                                                                                                                                1/6 
  正在安装    : docker-compose-plugin-2.24.5-1.el7.x86_64                                                                                                                                                                                          2/6 
  正在安装    : docker-buildx-plugin-0.12.1-1.el7.x86_64                                                                                                                                                                                           3/6 
  正在安装    : 1:docker-ce-cli-24.0.7-1.el7.x86_64                                                                                                                                                                                                4/6 
  正在安装    : docker-ce-rootless-extras-25.0.2-1.el7.x86_64                                                                                                                                                                                      5/6 
  正在安装    : 3:docker-ce-24.0.7-1.el7.x86_64                                                                                                                                                                                                    6/6 
  验证中      : docker-buildx-plugin-0.12.1-1.el7.x86_64                                                                                                                                                                                           1/6 
  验证中      : 3:docker-ce-24.0.7-1.el7.x86_64                                                                                                                                                                                                    2/6 
  验证中      : docker-compose-plugin-2.24.5-1.el7.x86_64                                                                                                                                                                                          3/6 
  验证中      : containerd.io-1.6.28-3.1.el7.x86_64                                                                                                                                                                                                4/6 
  验证中      : docker-ce-rootless-extras-25.0.2-1.el7.x86_64                                                                                                                                                                                      5/6 
  验证中      : 1:docker-ce-cli-24.0.7-1.el7.x86_64                                                                                                                                                                                                6/6 

已安装:
  containerd.io.x86_64 0:1.6.28-3.1.el7           docker-buildx-plugin.x86_64 0:0.12.1-1.el7           docker-ce.x86_64 3:24.0.7-1.el7           docker-ce-cli.x86_64 1:24.0.7-1.el7           docker-compose-plugin.x86_64 0:2.24.5-1.el7          

作为依赖被安装:
  docker-ce-rootless-extras.x86_64 0:25.0.2-1.el7                                                                                                                                                                                                      

完毕!
[20240206 01:25:52] [Info] 安装Docker:5.启动docker并设置开机自启
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since 二 2024-02-06 01:26:43 EST; 5ms ago
     Docs: https://docs.docker.com
 Main PID: 16254 (dockerd)
    Tasks: 10
   Memory: 31.6M
   CGroup: /system.slice/docker.service
           └─16254 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

2月 06 01:26:42 localhost.localdomain systemd[1]: Starting Docker Application Container Engine...
2月 06 01:26:42 localhost.localdomain dockerd[16254]: time="2024-02-06T01:26:42.702034175-05:00" level=info msg="Starting up"
2月 06 01:26:43 localhost.localdomain dockerd[16254]: time="2024-02-06T01:26:43.693937724-05:00" level=info msg="Loading containers: start."
2月 06 01:26:43 localhost.localdomain dockerd[16254]: time="2024-02-06T01:26:43.754164823-05:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be used to set a preferred IP address"
2月 06 01:26:43 localhost.localdomain dockerd[16254]: time="2024-02-06T01:26:43.784660263-05:00" level=info msg="Loading containers: done."
2月 06 01:26:43 localhost.localdomain dockerd[16254]: time="2024-02-06T01:26:43.800863108-05:00" level=info msg="Docker daemon" commit=311b9ff graphdriver=overlay2 version=24.0.7
2月 06 01:26:43 localhost.localdomain dockerd[16254]: time="2024-02-06T01:26:43.800948561-05:00" level=info msg="Daemon has completed initialization"
2月 06 01:26:43 localhost.localdomain dockerd[16254]: time="2024-02-06T01:26:43.834235503-05:00" level=info msg="API listen on /run/docker.sock"
2月 06 01:26:43 localhost.localdomain systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.
[20240206 01:25:52] [Info] 安装Docker:END.完成.安装版本如下:
Client: Docker Engine - Community
 Version:           24.0.7
 API version:       1.43
 Go version:        go1.20.10
 Git commit:        afdd53b
 Built:             Thu Oct 26 09:11:35 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          24.0.7
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.10
  Git commit:       311b9ff
  Built:            Thu Oct 26 09:10:36 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.28
  GitCommit:        ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc:
  Version:          1.1.12
  GitCommit:        v1.1.12-0-g51d5e94
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
[20240206 01:25:52] [Info] #########################################################################################
[20240206 01:25:52] [Info] ############################## Start Install cri-dockerd... #############################
[20240206 01:25:52] [Info] #########################################################################################
[20240206 01:25:52] [Info] 准备安装cri-dockerd
准备中...                          ################################# [100%]
正在升级/安装...
   1:cri-dockerd-3:0.3.9-3.el7        ################################# [100%]
Created symlink from /etc/systemd/system/multi-user.target.wants/cri-docker.service to /usr/lib/systemd/system/cri-docker.service.
[20240206 01:25:52] [Info] #########################################################################################
[20240206 01:25:52] [Info] ################################## Start Install K8s... #################################
[20240206 01:25:52] [Info] #########################################################################################
[20240206 01:25:52] [Info] 准备安装k8s,版本:v1.28.2
[20240206 01:25:52] [Info] 安装k8s:1.阿里云YUM源
[20240206 01:25:52] [Info] 安装k8s:2.卸载旧版本
已加载插件:fastestmirror
参数 kubelet 没有匹配
参数 kubeadm 没有匹配
参数 kubectl 没有匹配
不删除任何软件包
[20240206 01:25:52] [Info] 安装k8s:3.安装kubele-t1.28.2、kubeadm-1.28.2、kubectl-1.28.2 指定版本
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.ustc.edu.cn
kubernetes                                                                                                                                                                                                                      | 1.4 kB  00:00:00     
正在解决依赖关系
--> 正在检查事务
---> 软件包 kubeadm.x86_64.0.1.28.2-0 将被 安装
--> 正在处理依赖关系 kubernetes-cni >= 0.8.6,它被软件包 kubeadm-1.28.2-0.x86_64 需要
---> 软件包 kubectl.x86_64.0.1.28.2-0 将被 安装
---> 软件包 kubelet.x86_64.0.1.28.2-0 将被 安装
--> 正在检查事务
---> 软件包 kubernetes-cni.x86_64.0.1.2.0-0 将被 安装
--> 解决依赖关系完成

依赖关系解决

=======================================================================================================================================================================================================================================================
 Package                                                         架构                                                    版本                                                        源                                                           大小
=======================================================================================================================================================================================================================================================
正在安装:
 kubeadm                                                         x86_64                                                  1.28.2-0                                                    kubernetes                                                   11 M
 kubectl                                                         x86_64                                                  1.28.2-0                                                    kubernetes                                                   11 M
 kubelet                                                         x86_64                                                  1.28.2-0                                                    kubernetes                                                   21 M
为依赖而安装:
 kubernetes-cni                                                  x86_64                                                  1.2.0-0                                                     kubernetes                                                   17 M

事务概要
=======================================================================================================================================================================================================================================================
安装  3 软件包 (+1 依赖软件包)

总下载量:59 M
安装大小:250 M
Downloading packages:
(1/4): a24e42254b5a14b67b58c4633d29c27370c28ed6796a80c455a65acc813ff374-kubectl-1.28.2-0.x86_64.rpm                                                                                                                             |  11 MB  00:00:05     
(2/4): cee73f8035d734e86f722f77f1bf4e7d643e78d36646fd000148deb8af98b61c-kubeadm-1.28.2-0.x86_64.rpm                                                                                                                             |  11 MB  00:00:06     
(3/4): 0f2a2afd740d476ad77c508847bad1f559afc2425816c1f2ce4432a62dfe0b9d-kubernetes-cni-1.2.0-0.x86_64.rpm                                                                                                                       |  17 MB  00:00:08     
(4/4): e1cae938e231bffa3618f5934a096bd85372ee9b1293081f5682a22fe873add8-kubelet-1.28.2-0.x86_64.rpm                                                                                                                             |  21 MB  00:00:10     
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                                                                                                                                   3.7 MB/s |  59 MB  00:00:16     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
警告:RPM 数据库已被非 yum 程序修改。
  正在安装    : kubernetes-cni-1.2.0-0.x86_64                                                                                                                                                                                                      1/4 
  正在安装    : kubelet-1.28.2-0.x86_64                                                                                                                                                                                                            2/4 
  正在安装    : kubectl-1.28.2-0.x86_64                                                                                                                                                                                                            3/4 
  正在安装    : kubeadm-1.28.2-0.x86_64                                                                                                                                                                                                            4/4 
  验证中      : kubelet-1.28.2-0.x86_64                                                                                                                                                                                                            1/4 
  验证中      : kubectl-1.28.2-0.x86_64                                                                                                                                                                                                            2/4 
  验证中      : kubernetes-cni-1.2.0-0.x86_64                                                                                                                                                                                                      3/4 
  验证中      : kubeadm-1.28.2-0.x86_64                                                                                                                                                                                                            4/4 

已安装:
  kubeadm.x86_64 0:1.28.2-0                                                         kubectl.x86_64 0:1.28.2-0                                                         kubelet.x86_64 0:1.28.2-0                                                        

作为依赖被安装:
  kubernetes-cni.x86_64 0:1.2.0-0                                                                                                                                                                                                                      

完毕!
[20240206 01:25:52] [Info] 安装k8s:4.开机启动kubelet
[20240206 01:25:52] [Info] 安装k8s:5.指定容器unix:///var/run/cri-dockerd.sock
W0206 01:27:10.471373   16927 preflight.go:56] [reset] WARNING: Changes made to this host by 'kubeadm init' or 'kubeadm join' will be reverted.
[reset] Are you sure you want to proceed? [y/N]: y
[preflight] Running pre-flight checks
W0206 01:27:25.283590   16927 removeetcdmember.go:106] [reset] No kubeadm config, using etcd pod spec to get data directory
[reset] Deleted contents of the etcd data directory: /var/lib/etcd
[reset] Stopping the kubelet service
[reset] Unmounting mounted directories in "/var/lib/kubelet"
[reset] Deleting contents of directories: [/etc/kubernetes/manifests /var/lib/kubelet /etc/kubernetes/pki]
[reset] Deleting files: [/etc/kubernetes/admin.conf /etc/kubernetes/kubelet.conf /etc/kubernetes/bootstrap-kubelet.conf /etc/kubernetes/controller-manager.conf /etc/kubernetes/scheduler.conf]

The reset process does not clean CNI configuration. To do so, you must remove /etc/cni/net.d

The reset process does not reset or clean up iptables rules or IPVS tables.
If you wish to reset iptables, you must do so manually by using the "iptables" command.

If your cluster was setup to utilize IPVS, run ipvsadm --clear (or similar)
to reset your system's IPVS tables.

The reset process does not clean your kubeconfig files and you must remove them manually.
Please, check the contents of the $HOME/.kube/config file.
当前节点为Master:10.8.42.15,需特殊配置或安装:
[20240206 01:25:52] [Info] #########################################################################################
[20240206 01:25:52] [Info] ############################### Master主节点启动集群... ##################################
[20240206 01:25:52] [Info] #########################################################################################
[20240206 01:25:52] [Info] 安装k8s_主节点_启动集群:拉取所 k8s 需要的容器镜像
[config/images] Pulled registry.aliyuncs.com/google_containers/kube-apiserver:v1.28.2
[config/images] Pulled registry.aliyuncs.com/google_containers/kube-controller-manager:v1.28.2
[config/images] Pulled registry.aliyuncs.com/google_containers/kube-scheduler:v1.28.2
[config/images] Pulled registry.aliyuncs.com/google_containers/kube-proxy:v1.28.2
[config/images] Pulled registry.aliyuncs.com/google_containers/pause:3.9
[config/images] Pulled registry.aliyuncs.com/google_containers/etcd:3.5.9-0
[config/images] Pulled registry.aliyuncs.com/google_containers/coredns:v1.10.1
[20240206 01:25:52] [Info] 安装k8s_主节点_启动集群:现有镜像
REPOSITORY                                                        TAG       IMAGE ID       CREATED         SIZE
registry.aliyuncs.com/google_containers/kube-apiserver            v1.28.2   cdcab12b2dd1   4 months ago    126MB
registry.aliyuncs.com/google_containers/kube-controller-manager   v1.28.2   55f13c92defb   4 months ago    122MB
registry.aliyuncs.com/google_containers/kube-scheduler            v1.28.2   7a5d9d67a13f   4 months ago    60.1MB
registry.aliyuncs.com/google_containers/kube-proxy                v1.28.2   c120fed2beb8   4 months ago    73.1MB
registry.aliyuncs.com/google_containers/etcd                      3.5.9-0   73deb9a3f702   8 months ago    294MB
registry.aliyuncs.com/google_containers/coredns                   v1.10.1   ead0a4a53df8   12 months ago   53.6MB
registry.aliyuncs.com/google_containers/pause                     3.9       e6f181688397   16 months ago   744kB
[20240206 01:25:52] [Info] 安装k8s_主节点_启动集群:初始化
[init] Using Kubernetes version: v1.28.2
[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 [k8smaster kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 10.8.42.15]
[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 [k8smaster localhost] and IPs [10.8.42.15 127.0.0.1 ::1]
[certs] Generating "etcd/peer" certificate and key
[certs] etcd/peer serving cert is signed for DNS names [k8smaster localhost] and IPs [10.8.42.15 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
[etcd] Creating static Pod manifest for local etcd in "/etc/kubernetes/manifests"
[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"
[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
[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 4.501826 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 k8smaster 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 k8smaster as control-plane by adding the taints [node-role.kubernetes.io/control-plane:NoSchedule]
[bootstrap-token] Using token: abcdef.0123456789abcdef
[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-proxy

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/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config

Alternatively, if you are the root user, you can run:

  export KUBECONFIG=/etc/kubernetes/admin.conf

You 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 10.8.42.15:6443 --token abcdef.0123456789abcdef \
        --discovery-token-ca-cert-hash sha256:dcb3a92796f3e28eeea7fa4200568da048a20e37f2ccdbb7953db6ac0ecd8804 
[20240206 01:25:52] [Info] 安装k8s_主节点_启动集群:根据初始化提示执行,集群应用客户端管理集群文件准备
/etc/kubernetes/admin.conf
[20240206 01:25:52] [Info] 安装k8s_主节点_启动集群:配置网络插件flannel
namespace/kube-flannel created
serviceaccount/flannel created
clusterrole.rbac.authorization.k8s.io/flannel created
clusterrolebinding.rbac.authorization.k8s.io/flannel created
configmap/kube-flannel-cfg created
daemonset.apps/kube-flannel-ds created
[20240206 01:25:52] [Info] 安装k8s_主节点_启动集群:可视化界面
Unable to find image 'eipwork/kuboard:v3.5.2.6' locally
v3.5.2.6: Pulling from eipwork/kuboard
39cf15d1b231: Pull complete 
2ede31ac16cf: Pull complete 
7c8ca322b862: Pull complete 
41babe9af3c7: Pull complete 
1b483e04f7f8: Pull complete 
cc94ac4a24df: Pull complete 
dc148a404358: Pull complete 
a742d61437e3: Pull complete 
ae3b6d8cfd32: Pull complete 
ba1a1e94e760: Pull complete 
7db3c90d5c13: Pull complete 
5fc438952344: Pull complete 
9e7f80931110: Pull complete 
257cbd88320b: Pull complete 
12647d10952c: Pull complete 
fcefba48defe: Pull complete 
d6c13d205407: Pull complete 
25f508b5b9d4: Pull complete 
Digest: sha256:0501a4840e4e3b76619866cdee946c3ad64ace03e8f73f4aef376906f661137b
Status: Downloaded newer image for eipwork/kuboard:v3.5.2.6
465b98196e4c38d73e6987170909060105ad84b91b3459bcbfac49ef7b147e71
2.3.2. Node安装日志

日志最后看到“使用kubeadm join ip:port -- token 语法将当前Node加入集群管理。”说明子节点也安装成功!

[root@k8snode1 home]# ./install-k8s.sh
Hello, Let's Go!
[20240206 14:30:36] [Info] #########################################################################################
[20240206 14:30:36] [Info] ################################# 初始化服务器环境设置... ################################
[20240206 14:30:36] [Info] #########################################################################################
[20240206 14:30:36] [Info] 1.关闭用防火墙
[20240206 14:30:36] [Info] 2.配置域名解析
[20240206 14:30:36] [Info] 确认hosts域名配置--

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6 
10.8.42.15 k8smaster
10.8.42.16 k8snode1
10.8.42.17 k8snode2
以上↑↑↑↑↑↑↑主机配置hosts是否正确?默认为 no. Enter [yes/no]:yes
[20240206 14:30:36] [Info] 确认已配置hosts
[20240206 14:30:36] [Info] 3.必须关闭swap分区
[20240206 14:30:36] [Info] 4.临时关闭selinux防火墙
[20240206 14:30:36] [Info] 5.配置服务器时间保持一致[工具:chrony]
已加载插件:fastestmirror
Repository kubernetes is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.ustc.edu.cn
软件包 chrony-3.4-1.el7.x86_64 已安装并且是最新版本
无须任何处理
210 Number of sources = 4
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^+ dns2.synet.edu.cn             1  10   365   377    +12ms[  +12ms] +/-   34ms
^* time.neu.edu.cn               1  10   377   240    +11ms[  +11ms] +/-   33ms
^- ntp8.flashdance.cx            2  10   337   729    -27ms[  -27ms] +/-  137ms
^- makaki2.miuku.net             3  10   167   178    +23ms[  +23ms] +/-  102ms
2024年 02月 06日 星期二 14:30:39 CST
[20240206 14:30:36] [Info] 6.添加网桥过滤和地址转发功能
[20240206 14:30:36] [Info] 6.1.添加网桥过滤和地址转发功能:添加配置
overlay
br_netfilter
net.bridge.bridge-nf-call-ip6tables=1
net.bridge.bridge-nf-call-iptables=1
net.ipv4.ip_forward=1
# 下面的内核参数可以解决ipvs模式下长连接空闲超时的问题
net.ipv4.tcp_keepalive_intvl=30
net.ipv4.tcp_keepalive_probes=10
net.ipv4.tcp_keepalive_time=600
vm.swappiness=0
[20240206 14:30:36] [Info] 6.2.添加网桥过滤和地址转发功能:重新加载配置
* Applying /usr/lib/sysctl.d/00-system.conf ...
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0
* Applying /usr/lib/sysctl.d/10-default-yama-scope.conf ...
kernel.yama.ptrace_scope = 0
* Applying /usr/lib/sysctl.d/50-default.conf ...
kernel.sysrq = 16
kernel.core_uses_pid = 1
kernel.kptr_restrict = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.promote_secondaries = 1
net.ipv4.conf.all.promote_secondaries = 1
fs.protected_hardlinks = 1
fs.protected_symlinks = 1
* Applying /etc/sysctl.d/99-sysctl.conf ...
* Applying /etc/sysctl.d/k8s.conf ...
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
net.ipv4.tcp_keepalive_intvl = 30
net.ipv4.tcp_keepalive_probes = 10
net.ipv4.tcp_keepalive_time = 600
vm.swappiness = 0
* Applying /etc/sysctl.conf ...
[20240206 14:30:36] [Info] 6.3.添加网桥过滤和地址转发功能:加载网桥过滤器模块
[20240206 14:30:36] [Info] 6.4.添加网桥过滤和地址转发功能:确认 br_netfilter 和 overlay 模块被加载
br_netfilter           22256  0 
bridge                151336  1 br_netfilter
overlay                91659  0 
[20240206 14:30:36] [Info] 6.5.添加网桥过滤和地址转发功能:确认系统变量在你的 sysctl 配置中被设置为 1
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1
[20240206 14:30:36] [Info] 7.配置ipvs功能
[20240206 14:30:36] [Info] 7.1.配置ipvs功能:安装ipset和ipvsadm
已加载插件:fastestmirror
Repository kubernetes is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.ustc.edu.cn
软件包 ipvsadm-1.27-8.el7.x86_64 已安装并且是最新版本
软件包 ipset-7.1-1.el7.x86_64 已安装并且是最新版本
软件包 sysstat-10.1.5-20.el7_9.x86_64 已安装并且是最新版本
软件包 conntrack-tools-1.4.4-7.el7.x86_64 已安装并且是最新版本
无须任何处理
[20240206 14:30:36] [Info] 7.2.配置ipvs功能:添加需要加载的模块写入脚本文件
[20240206 14:30:36] [Info] 7.3.配置ipvs功能:重启服务
[20240206 14:30:36] [Info] 7.4.配置ipvs功能:查看对应的模块是否加载成功
nf_conntrack_netlink    36396  0 
nf_conntrack_ipv6      18935  2 
nf_defrag_ipv6         35104  1 nf_conntrack_ipv6
nf_conntrack_ipv4      15053  4 
nf_defrag_ipv4         12729  1 nf_conntrack_ipv4
ip_vs_sh               12688  0 
ip_vs_wrr              12697  0 
ip_vs_rr               12600  4 
ip_vs                 145458  10 ip_vs_rr,ip_vs_sh,ip_vs_wrr
nf_conntrack          139264  10 ip_vs,nf_nat,nf_nat_ipv4,nf_nat_ipv6,xt_conntrack,nf_nat_masquerade_ipv4,nf_nat_masquerade_ipv6,nf_conntrack_netlink,nf_conntrack_ipv4,nf_conntrack_ipv6
nfnetlink              14519  3 nf_tables,ip_set,nf_conntrack_netlink
libcrc32c              12644  4 xfs,ip_vs,nf_nat,nf_conntrack
[20240206 14:30:36] [Info] #########################################################################################
[20240206 14:30:36] [Info] ################################# Start Install Docker... ###############################
[20240206 14:30:36] [Info] #########################################################################################
[20240206 14:30:36] [Info] 准备安装Docker,版本:24.0.7
[20240206 14:30:36] [Info] 安装Docker:1.yum-utils软件用于提供yum-config-manager程序
已加载插件:fastestmirror
Repository kubernetes is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.ustc.edu.cn
软件包 yum-utils-1.1.31-54.el7_8.noarch 已安装并且是最新版本
无须任何处理
[20240206 14:30:36] [Info] 安装Docker:2.使用yum-config-manager创建docker阿里存储库
已加载插件:fastestmirror
Repository kubernetes is listed more than once in the configuration
adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
已加载插件:fastestmirror
Repository kubernetes is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.ustc.edu.cn
base                                                                                                                                                                                                                            | 3.6 kB  00:00:00     
docker-ce-stable                                                                                                                                                                                                                | 3.5 kB  00:00:00     
extras                                                                                                                                                                                                                          | 2.9 kB  00:00:00     
kubernetes                                                                                                                                                                                                                      | 1.4 kB  00:00:00     
updates                                                                                                                                                                                                                         | 2.9 kB  00:00:00     
元数据缓存已建立
[20240206 14:30:36] [Info] 安装Docker:3.配置Docker镜像加速器/修改cgroup方式
[20240206 14:30:36] [Info] 安装Docker:4.开始执行安装
已加载插件:fastestmirror
Repository kubernetes is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.ustc.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 containerd.io.x86_64.0.1.6.28-3.1.el7 将被 安装
---> 软件包 docker-buildx-plugin.x86_64.0.0.12.1-1.el7 将被 安装
---> 软件包 docker-ce.x86_64.3.24.0.7-1.el7 将被 安装
--> 正在处理依赖关系 docker-ce-rootless-extras,它被软件包 3:docker-ce-24.0.7-1.el7.x86_64 需要
---> 软件包 docker-ce-cli.x86_64.1.24.0.7-1.el7 将被 安装
---> 软件包 docker-compose-plugin.x86_64.0.2.24.5-1.el7 将被 安装
--> 正在检查事务
---> 软件包 docker-ce-rootless-extras.x86_64.0.25.0.2-1.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

=======================================================================================================================================================================================================================================================
 Package                                                              架构                                              版本                                                         源                                                           大小
=======================================================================================================================================================================================================================================================
正在安装:
 containerd.io                                                        x86_64                                            1.6.28-3.1.el7                                               docker-ce-stable                                             35 M
 docker-buildx-plugin                                                 x86_64                                            0.12.1-1.el7                                                 docker-ce-stable                                             13 M
 docker-ce                                                            x86_64                                            3:24.0.7-1.el7                                               docker-ce-stable                                             24 M
 docker-ce-cli                                                        x86_64                                            1:24.0.7-1.el7                                               docker-ce-stable                                             13 M
 docker-compose-plugin                                                x86_64                                            2.24.5-1.el7                                                 docker-ce-stable                                             13 M
为依赖而安装:
 docker-ce-rootless-extras                                            x86_64                                            25.0.2-1.el7                                                 docker-ce-stable                                            9.4 M

事务概要
=======================================================================================================================================================================================================================================================
安装  5 软件包 (+1 依赖软件包)

总下载量:108 M
安装大小:380 M
Downloading packages:
(1/6): docker-buildx-plugin-0.12.1-1.el7.x86_64.rpm                                                                                                                                                                             |  13 MB  00:00:08     
(2/6): containerd.io-1.6.28-3.1.el7.x86_64.rpm                                                                                                                                                                                  |  35 MB  00:00:19     
(3/6): docker-ce-24.0.7-1.el7.x86_64.rpm                                                                                                                                                                                        |  24 MB  00:00:16     
(4/6): docker-ce-cli-24.0.7-1.el7.x86_64.rpm                                                                                                                                                                                    |  13 MB  00:00:08     
(5/6): docker-ce-rootless-extras-25.0.2-1.el7.x86_64.rpm                                                                                                                                                                        | 9.4 MB  00:00:09     
(6/6): docker-compose-plugin-2.24.5-1.el7.x86_64.rpm                                                                                                                                                                            |  13 MB  00:00:07     
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                                                                                                                                   3.0 MB/s | 108 MB  00:00:36     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : containerd.io-1.6.28-3.1.el7.x86_64                                                                                                                                                                                                1/6 
  正在安装    : docker-compose-plugin-2.24.5-1.el7.x86_64                                                                                                                                                                                          2/6 
  正在安装    : docker-buildx-plugin-0.12.1-1.el7.x86_64                                                                                                                                                                                           3/6 
  正在安装    : 1:docker-ce-cli-24.0.7-1.el7.x86_64                                                                                                                                                                                                4/6 
  正在安装    : docker-ce-rootless-extras-25.0.2-1.el7.x86_64                                                                                                                                                                                      5/6 
  正在安装    : 3:docker-ce-24.0.7-1.el7.x86_64                                                                                                                                                                                                    6/6 
  验证中      : docker-buildx-plugin-0.12.1-1.el7.x86_64                                                                                                                                                                                           1/6 
  验证中      : 3:docker-ce-24.0.7-1.el7.x86_64                                                                                                                                                                                                    2/6 
  验证中      : docker-compose-plugin-2.24.5-1.el7.x86_64                                                                                                                                                                                          3/6 
  验证中      : containerd.io-1.6.28-3.1.el7.x86_64                                                                                                                                                                                                4/6 
  验证中      : docker-ce-rootless-extras-25.0.2-1.el7.x86_64                                                                                                                                                                                      5/6 
  验证中      : 1:docker-ce-cli-24.0.7-1.el7.x86_64                                                                                                                                                                                                6/6 

已安装:
  containerd.io.x86_64 0:1.6.28-3.1.el7           docker-buildx-plugin.x86_64 0:0.12.1-1.el7           docker-ce.x86_64 3:24.0.7-1.el7           docker-ce-cli.x86_64 1:24.0.7-1.el7           docker-compose-plugin.x86_64 0:2.24.5-1.el7          

作为依赖被安装:
  docker-ce-rootless-extras.x86_64 0:25.0.2-1.el7                                                                                                                                                                                                      

完毕!
[20240206 14:30:36] [Info] 安装Docker:5.启动docker并设置开机自启
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since 二 2024-02-06 14:31:33 CST; 5ms ago
     Docs: https://docs.docker.com
 Main PID: 7984 (dockerd)
    Tasks: 10
   Memory: 31.4M
   CGroup: /system.slice/docker.service
           └─7984 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

2月 06 14:31:32 k8snode1 systemd[1]: Starting Docker Application Container Engine...
2月 06 14:31:32 k8snode1 dockerd[7984]: time="2024-02-06T14:31:32.811930610+08:00" level=info msg="Starting up"
2月 06 14:31:33 k8snode1 dockerd[7984]: time="2024-02-06T14:31:33.828108957+08:00" level=info msg="Loading containers: start."
2月 06 14:31:33 k8snode1 dockerd[7984]: time="2024-02-06T14:31:33.887577275+08:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be used to set a preferred IP address"
2月 06 14:31:33 k8snode1 dockerd[7984]: time="2024-02-06T14:31:33.921652410+08:00" level=info msg="Loading containers: done."
2月 06 14:31:33 k8snode1 dockerd[7984]: time="2024-02-06T14:31:33.936547822+08:00" level=info msg="Docker daemon" commit=311b9ff graphdriver=overlay2 version=24.0.7
2月 06 14:31:33 k8snode1 dockerd[7984]: time="2024-02-06T14:31:33.936639591+08:00" level=info msg="Daemon has completed initialization"
2月 06 14:31:33 k8snode1 dockerd[7984]: time="2024-02-06T14:31:33.969004794+08:00" level=info msg="API listen on /run/docker.sock"
2月 06 14:31:33 k8snode1 systemd[1]: Started Docker Application Container Engine.
[20240206 14:30:36] [Info] 安装Docker:END.完成.安装版本如下:
Client: Docker Engine - Community
 Version:           24.0.7
 API version:       1.43
 Go version:        go1.20.10
 Git commit:        afdd53b
 Built:             Thu Oct 26 09:11:35 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          24.0.7
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.10
  Git commit:       311b9ff
  Built:            Thu Oct 26 09:10:36 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.6.10
  GitCommit:        770bd0108c32f3fb5c73ae1264f7e503fe7b2661
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d1
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
[20240206 14:30:36] [Info] #########################################################################################
[20240206 14:30:36] [Info] ############################## Start Install cri-dockerd... #############################
[20240206 14:30:36] [Info] #########################################################################################
[20240206 14:30:36] [Info] 准备安装cri-dockerd
准备中...                          ################################# [100%]
正在升级/安装...
   1:cri-dockerd-3:0.3.9-3.el7        ################################# [100%]
Created symlink from /etc/systemd/system/multi-user.target.wants/cri-docker.service to /usr/lib/systemd/system/cri-docker.service.
[20240206 14:30:36] [Info] #########################################################################################
[20240206 14:30:36] [Info] ################################## Start Install K8s... #################################
[20240206 14:30:36] [Info] #########################################################################################
[20240206 14:30:36] [Info] 准备安装k8s,版本:v1.28.2
[20240206 14:30:36] [Info] 安装k8s:1.阿里云YUM源
[20240206 14:30:36] [Info] 安装k8s:2.卸载旧版本
已加载插件:fastestmirror
Repository kubernetes is listed more than once in the configuration
参数 kubelet 没有匹配
参数 kubeadm 没有匹配
参数 kubectl 没有匹配
不删除任何软件包
[20240206 14:30:36] [Info] 安装k8s:3.安装kubele-t1.28.2、kubeadm-1.28.2、kubectl-1.28.2 指定版本
已加载插件:fastestmirror
Repository kubernetes is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.ustc.edu.cn
kubernetes                                                                                                                                                                                                                      | 1.4 kB  00:00:00     
正在解决依赖关系
--> 正在检查事务
---> 软件包 kubeadm.x86_64.0.1.28.2-0 将被 安装
--> 正在处理依赖关系 kubernetes-cni >= 0.8.6,它被软件包 kubeadm-1.28.2-0.x86_64 需要
---> 软件包 kubectl.x86_64.0.1.28.2-0 将被 安装
---> 软件包 kubelet.x86_64.0.1.28.2-0 将被 安装
--> 正在检查事务
---> 软件包 kubernetes-cni.x86_64.0.1.2.0-0 将被 安装
--> 解决依赖关系完成

依赖关系解决

=======================================================================================================================================================================================================================================================
 Package                                                         架构                                                    版本                                                        源                                                           大小
=======================================================================================================================================================================================================================================================
正在安装:
 kubeadm                                                         x86_64                                                  1.28.2-0                                                    kubernetes                                                   11 M
 kubectl                                                         x86_64                                                  1.28.2-0                                                    kubernetes                                                   11 M
 kubelet                                                         x86_64                                                  1.28.2-0                                                    kubernetes                                                   21 M
为依赖而安装:
 kubernetes-cni                                                  x86_64                                                  1.2.0-0                                                     kubernetes                                                   17 M

事务概要
=======================================================================================================================================================================================================================================================
安装  3 软件包 (+1 依赖软件包)

总下载量:59 M
安装大小:250 M
Downloading packages:
(1/4): a24e42254b5a14b67b58c4633d29c27370c28ed6796a80c455a65acc813ff374-kubectl-1.28.2-0.x86_64.rpm                                                                                                                             |  11 MB  00:00:06     
(2/4): cee73f8035d734e86f722f77f1bf4e7d643e78d36646fd000148deb8af98b61c-kubeadm-1.28.2-0.x86_64.rpm                                                                                                                             |  11 MB  00:00:08     
(3/4): e1cae938e231bffa3618f5934a096bd85372ee9b1293081f5682a22fe873add8-kubelet-1.28.2-0.x86_64.rpm                                                                                                                             |  21 MB  00:00:12     
(4/4): 0f2a2afd740d476ad77c508847bad1f559afc2425816c1f2ce4432a62dfe0b9d-kubernetes-cni-1.2.0-0.x86_64.rpm                                                                                                                       |  17 MB  00:00:12     
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                                                                                                                                   2.8 MB/s |  59 MB  00:00:21     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
警告:RPM 数据库已被非 yum 程序修改。
  正在安装    : kubernetes-cni-1.2.0-0.x86_64                                                                                                                                                                                                      1/4 
  正在安装    : kubelet-1.28.2-0.x86_64                                                                                                                                                                                                            2/4 
  正在安装    : kubectl-1.28.2-0.x86_64                                                                                                                                                                                                            3/4 
  正在安装    : kubeadm-1.28.2-0.x86_64                                                                                                                                                                                                            4/4 
  验证中      : kubelet-1.28.2-0.x86_64                                                                                                                                                                                                            1/4 
  验证中      : kubectl-1.28.2-0.x86_64                                                                                                                                                                                                            2/4 
  验证中      : kubernetes-cni-1.2.0-0.x86_64                                                                                                                                                                                                      3/4 
  验证中      : kubeadm-1.28.2-0.x86_64                                                                                                                                                                                                            4/4 

已安装:
  kubeadm.x86_64 0:1.28.2-0                                                         kubectl.x86_64 0:1.28.2-0                                                         kubelet.x86_64 0:1.28.2-0                                                        

作为依赖被安装:
  kubernetes-cni.x86_64 0:1.2.0-0                                                                                                                                                                                                                      

完毕!
[20240206 14:30:36] [Info] 安装k8s:4.开机启动kubelet
[20240206 14:30:36] [Info] 安装k8s:5.指定容器unix:///var/run/cri-dockerd.sock
W0206 14:32:06.720581    9535 preflight.go:56] [reset] WARNING: Changes made to this host by 'kubeadm init' or 'kubeadm join' will be reverted.
[reset] Are you sure you want to proceed? [y/N]: y
[preflight] Running pre-flight checks
W0206 14:36:06.783725    9535 removeetcdmember.go:106] [reset] No kubeadm config, using etcd pod spec to get data directory
[reset] Deleted contents of the etcd data directory: /var/lib/etcd
[reset] Stopping the kubelet service
[reset] Unmounting mounted directories in "/var/lib/kubelet"
[reset] Deleting contents of directories: [/etc/kubernetes/manifests /var/lib/kubelet /etc/kubernetes/pki]
[reset] Deleting files: [/etc/kubernetes/admin.conf /etc/kubernetes/kubelet.conf /etc/kubernetes/bootstrap-kubelet.conf /etc/kubernetes/controller-manager.conf /etc/kubernetes/scheduler.conf]

The reset process does not clean CNI configuration. To do so, you must remove /etc/cni/net.d

The reset process does not reset or clean up iptables rules or IPVS tables.
If you wish to reset iptables, you must do so manually by using the "iptables" command.

If your cluster was setup to utilize IPVS, run ipvsadm --clear (or similar)
to reset your system's IPVS tables.

The reset process does not clean your kubeconfig files and you must remove them manually.
Please, check the contents of the $HOME/.kube/config file.
[20240206 14:30:36] [Info] #########################################################################################
[20240206 14:30:36] [Info] ################################### Node join集群... ####################################
[20240206 14:30:36] [Info] #########################################################################################
请使用kubeadm join ip:port -- token 语法将当前Node加入集群管理。
请使用kubeadm join ip:port -- token 语法将当前Node加入集群管理。

3. 节点join集群

现在已经在Master、Node中安装部署了k8s,但是还没做集群管理,因此需要将Node Join到Master中。

通过Master安装日志中的信息,依次在各Node节点,执行Join命令:

kubeadm join 10.8.42.15:6443 --token abcdef.0123456789abcdef \
        --discovery-token-ca-cert-hash sha256:c4462505977ef38e27f0ba91c44a315242c9dac37a219a65cc53822e172ae26b \
	   --cri-socket unix:///var/run/cri-dockerd.sock

💡注意join末尾还需要指定:--cri-socket unix:///var/run/cri-dockerd.sock

💡若忘记token信息,则在主节点运行以下命令,重新获取:

#默认24H有效期
kubeadm token create --print-join-command

#永久token
kubeadm token create --ttl 0 --print-join-command

​​

Join后在可Master执行kubectl get node,查看K8s所有的节点:

[root@localhost home]# kubectl get node
NAME        STATUS   ROLES           AGE    VERSION
k8smaster   Ready    control-plane   113m   v1.28.2
k8snode1    Ready    <none>          104m   v1.28.2
k8snode2    Ready    <none>          96m    v1.28.2

到此,集群搭建完成!

4. 管理面板kuboard (可选)

在脚本中,Master主节点会默认安装kuboard多集群管理界面,方便管理k8s容器的一些基本的常用操作,包括服务部署、日志查看、负载导入导出等,虽然简单但是很实用。

使用教程详见官网:https://kuboard.cn/

Kuboard_Kubernetes教程_K8S安装_管理界面Kuboard是一款免费的Kubernetes管理界面_同时该网站还提供Kubernetes安装文档_K8S_部署_入门_免费中文Kubernetes教程_以及在Kubernetes上部署SpringCloud的详细文档icon-default.png?t=N7T8https://kuboard.cn/4.1. 登录

访问Master管理界面http://10.8.42.15/

#默认账号:admin

#默认密码:Kuboard123

4.2. 添加集群环境

点击+添加集群,根据提示,建议使用Token或kubeconfig方式,填写完后,点击确定即可。

​​

​​

4.3. 查看集群信息

​​

​​

4.4. 部署、伸缩等管理

​​

5.参考文献

《使用部署工具安装 Kubernetes》

https://kubernetes.io/zh-cn/docs/setup/production-environment/tools/kubeadm/install-kubeadm/

《K8S最新版本集群部署(v1.28) + 容器引擎Docker部署(下)》

https://blog.csdn.net/qq_36434219/article/details/132527054

《Kubernetes(k8s)最新版本安装部署》

https://zhuanlan.zhihu.com/p/651734154?utm_id=0

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1437647.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

微软.NET6开发的C#特性——类、结构体和联合体

我是荔园微风&#xff0c;作为一名在IT界整整25年的老兵&#xff0c;看到不少初学者在学习编程语言的过程中如此的痛苦&#xff0c;我决定做点什么&#xff0c;下面我就重点讲讲微软.NET6开发人员需要知道的C#特性。 C#经历了多年发展&#xff0c; 进行了多次重大创新&#xf…

python实现飞书群机器人消息通知(消息卡片)

python实现飞书群机器人消息通知 直接上代码 """ 飞书群机器人发送通知 """ import time import urllib3 import datetimeurllib3.disable_warnings()class FlybookRobotAlert():def __init__(self):self.webhook webhook_urlself.headers {…

机器学习系列——(十五)随机森林回归

引言 在机器学习的众多算法中&#xff0c;随机森林以其出色的准确率、对高维数据的处理能力以及对训练数据集的异常值的鲁棒性而广受欢迎。它是一种集成学习方法&#xff0c;通过构建多个决策树来进行预测和分类。本文将重点介绍随机森林在回归问题中的应用&#xff0c;即随机…

Python进阶--下载想要的格言(基于格言网的Python爬虫程序)

注&#xff1a;由于上篇帖子&#xff08;Python进阶--爬取下载人生格言(基于格言网的Python3爬虫)-CSDN博客&#xff09;篇幅长度的限制&#xff0c;此篇帖子对上篇做一个拓展延伸。 目录 一、爬取格言网中想要内容的url 1、找到想要的内容 2、抓包分析&#xff0c;找到想…

C++之std::tuple(一) : 使用精讲(全)

相关系列文章 C之std::tuple(一) : 使用精讲(全) C三剑客之std::variant(一) : 使用 C三剑客之std::variant(二)&#xff1a;深入剖析 深入理解可变参数(va_list、std::initializer_list和可变参数模版) std::apply源码分析 目录 1.简介 2.std::ignore介绍 3.创建元组 3.1.…

【极数系列】Flink集成KafkaSink 实时输出数据(11)

文章目录 01 引言02 连接器依赖2.1 kafka连接器依赖2.2 base基础依赖 03 使用方法04 序列化器05 指标监控06 项目源码实战6.1 包结构6.2 pom.xml依赖6.3 配置文件6.4 创建sink作业 01 引言 KafkaSink 可将数据流写入一个或多个 Kafka topic 实战源码地址,一键下载可用&#xf…

2024最新CleanMyMac X优化Mac电脑系统体验分享

使用Mac电脑的用户都希望它们能够保持最佳性能。但有时&#xff0c;你可能会发现你的Mac运行变慢或响应迟缓。这可能是由于几个原因造成的&#xff0c;包括硬盘空间不足、系统缓存堆积、以及过多的启动项等。解决了这些问题&#xff0c;你可以显著提升你的Mac性能。本文将探讨导…

寒假作业2024.2.7

1请编程实现二又树的操作 1.1二又树的创建 1.2二又树的先序遍历 1.3二又树的中序遍历 1.4二又树的后序遍历 1.5二又树各个节点度的个数 1.6二叉树的深度 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <…

【JS逆向六】(上)逆向模拟生成某网站的【sig】和【payload】的值 仅供学习

逆向日期&#xff1a;2024.02.07 使用工具&#xff1a;Node.js 加密方法&#xff1a;未知 / md5标准库 文章全程已做去敏处理&#xff01;&#xff01;&#xff01; 【需要做的可联系我】 可使用AES进行解密处理&#xff08; 直接解密即可&#xff09;&#xff1a;在线AES加解…

[HCIE]防火墙基础配置

实验目的&#xff1a;1.允许主机 ping FW的物理接口&#xff1b; 2.允许FW访问trust区域的主机&#xff1b; 3.允许trust主机访问其他所有区域。 配置步骤&#xff1a; 1.配置所有接口地址&#xff08;略&#xff09; 2.将防火墙接口加入到各自的区域 firewall zone trust …

企业数字化转型面临什么挑战?

随着科技的飞速发展&#xff0c;企业数字化转型已成为当今商业世界的一大趋势。然而&#xff0c;在这场变革中&#xff0c;企业可能会面临诸多挑战。本文将结合实际案例&#xff0c;探讨企业在数字化转型过程中可能遇到的一些问题&#xff0c;并提供相应的解决建议。 1.技术挑…

C# CAD交互界面-自定义窗体(三)

运行环境 vs2022 c# cad2016 调试成功 一、引用 二、开发代码进行详细的说明 初始化与获取AutoCAD核心对象&#xff1a; Database db HostApplicationServices.WorkingDatabase;&#xff1a;这行代码获取当前工作中的AutoCAD数据库对象。在AutoCAD中&#xff0c;所有图形数…

研发误删的库,凭什么要 DBA 承担责任

镇楼图 三个角色 删库以及更宽泛的数据库变更场景中有三个角色&#xff0c;业务研发&#xff0c;DBA 以及使用的数据库变更工具&#xff1a; 业务研发通常指的是后端研发。国内最主流的技术栈还是 Java&#xff0c;此外 Go 也有一部分&#xff0c;另有全栈的则使用 Node。这些…

如何开始深度学习,从实践开始

将“如何开始深度学习”这个问题喂给ChatGPT和文心一言&#xff0c;会给出很有专业水准的答案&#xff0c;比如&#xff1a; 要开始深度学习&#xff0c;你可以遵循以下步骤&#xff1a; 学习Python编程语言的基础知识&#xff0c;因为它在深度学习框架中经常被使用。 熟悉线性…

如何在GitHub上创建自己的个人网站【github.io】

如何在GitHub上创建自己的个人网站【github.io】 1.创建一个自己的GitHub账号2.点击New按钮3.填写个人仓库相关的信息并创建4.安装git&#xff0c;下载你需要的版本。5.上传新的文件6.访问网站7.后话 1.创建一个自己的GitHub账号 GitHub网站 最后会出现像下面一样的界面 2.点…

spring boot学习第十一篇:发邮件

1、pom.xml文件内容如下&#xff08;是我所有学习内容需要的&#xff0c;不再单独分出来&#xff0c;包不会冲突&#xff09;&#xff1a; <?xml version"1.0" encoding"UTF-8"?> <project xmlns"http://maven.apache.org/POM/4.0.0"…

基于Java农产品商城系统设计与实现(源码+部署文档)

博主介绍&#xff1a; ✌至今服务客户已经1000、专注于Java技术领域、项目定制、技术答疑、开发工具、毕业项目实战 ✌ &#x1f345; 文末获取源码联系 &#x1f345; &#x1f447;&#x1f3fb; 精彩专栏 推荐订阅 &#x1f447;&#x1f3fb; 不然下次找不到 Java项目精品实…

OpenCV-31 获得形态学卷积核

OpenCV提供了获取卷积核的API&#xff0c;不需要我们手动创建卷积核。 通过下面API---getStructuringElement(shape&#xff0c;ksize&#xff0c;[, anchor]) shape是指卷积核的型状&#xff0c;注意不是指长宽&#xff0c;是指卷积核中1形成的形状。MORPH_RECT 卷积核中的1…

内网远程控制——anydesk

而通常这个时候我们有权限修改anydesk的配置文件&#xff0c;这里进行测试&#xff0c;起两个虚拟机&#xff0c;设定一个场景&#xff08;攻击机拿到了webshell&#xff0c;受害机开着windows defender&#xff0c;如何去渗透拿到受害机权限&#xff09; 情景复现 这里拿到了…

C#(C Sharp)学习笔记_If条件判断语句【五】

前言&#xff1a; 本期学习的是编程语言中的主要语句&#xff1a;if-条件判断语句。在这里我们会学到&#xff1a;if语法&#xff0c;if-else&#xff0c;和if嵌套。话不多说&#xff0c;我们开始吧&#xff01; 什么是条件判断语句&#xff1f; 条件语句是用来判断给定的条件…