前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >KubeSphere 最佳实战:KubeKey 助力 Kubernetes 扩容控制节点实战指南

KubeSphere 最佳实战:KubeKey 助力 Kubernetes 扩容控制节点实战指南

原创
作者头像
运维有术
发布2024-07-20 07:39:01
430
发布2024-07-20 07:39:01
举报
文章被收录于专栏:运维有术

KubeSphere 最佳实战:KubeKey 助力 Kubernetes 扩容控制节点实战指南

2024 年云原生运维实战文档 99 篇原创计划 第 043 篇 |KubeSphere 最佳实战「2024」系列 第 015 篇

你好,欢迎来到运维有术

在近期的技术分享中,我们实战讨论了Kubernetes 集群 Worker 节点的扩容。文章发布后,我收到了社区成员的反馈,询问控制节点的扩容是否可行。我的回答是:绝对可以

今天,我将引导您模拟这个真实的生产环境需求,演示如何使用 KubeSphere 提供的 KubeKey 工具,将新的控制节点快速、无缝集成到现有的 Kubernetes 集群中。

虽然本文的操作示例以 openEuler 22.03 LTS SP3 操作系统为基础,但这套扩容策略和步骤同样适用于通过 KubeKey 部署的 Kubernetes 集群,无论它们运行在 CentOS、Ubuntu 还是其他主流 Linux 操作系统上。

实战服务器配置(架构1:1复刻小规模生产环境,配置略有不同)

主机名

IP

CPU

内存

系统盘

数据盘

用途

ksp-control-1

192.168.9.91

8

16

40

100

KubeSphere/k8s-control-plane/Worker

ksp-control-2

192.168.9.92

8

16

40

100

KubeSphere/k8s-control-plane/Worker

ksp-control-3

192.168.9.93

8

16

40

100

KubeSphere/k8s-control-plane/Worker

合计

3

24

48

120

300

实战环境涉及软件版本信息

  • 操作系统:openEuler 22.03 LTS SP3 x86_64
  • KubeSphere:v3.4.1
  • Kubernetes:v1.28.8
  • KubeKey: v3.1.2

1. 前置条件

1.1 部署单节点集群

首先,参考 征服 Docker 镜像访问限制!单节点 KubeSphere v3.4.1 部署攻略,安装部署一套单节点的 KubeSphere 和 Kubernetes 集群。

1.2 操作系统初始化配置

按照实战服务器规划配置,准备需要扩容的两个控制节点,并参考 Kubernetes 集群节点 openEuler 22.03 LTS SP3 系统初始化指南,完成操作系统初始化配置。

注意: 磁盘初始化时只需要配置 Containerd 对应的 /dev/sdb

初始化配置指南中没有涉及操作系统升级的任务,在能联网的环境初始化系统的时候一定要升级操作系统,然后重启节点。

2. 使用 KubeKey 扩容控制节点

接下来我们使用 KubeKey 将新增加的节点加入到已有的 Kubernetes 集群,参考官方说明文档,整个过程比较简单,仅需两步。

  • 修改 KubeKey 部署集群时使用的配置文件
  • 执行增加节点的命令

2.1 修改集群配置文件

登录 Control-1 节点,切换到部署集群时使用的 KubeKey 程序目录,修改原有的集群配置文件,我们实战中使用的名字为 ksp-v341-v1288.yaml,请根据实际情况修改 。

主要修改点:

  • spec.hosts:增加两条新的 Control 节点的信息。
  • spec.roleGroups.etcd:增加两条新的 Control 节点的信息
  • spec.roleGroups.control-plane:增加两条新的 Control 节点的信息
  • spec.roleGroups.worker:增加两条新的 Control 节点的信息

修改后的示例如下:

代码语言:yaml
复制
apiVersion: kubekey.kubesphere.io/v1alpha2
kind: Cluster
metadata:
  name: opsxlab
spec:
  hosts:
  - {name: ksp-control-1, address: 192.168.9.91, internalAddress: 192.168.9.91, user: root, password: "OpsXlab@2024"}
  - {name: ksp-control-2, address: 192.168.9.92, internalAddress: 192.168.9.92, user: root, password: "OpsXlab@2024"}
  - {name: ksp-control-3, address: 192.168.9.93, internalAddress: 192.168.9.93, user: root, password: "OpsXlab@2024"}
  roleGroups:
    etcd:
    - ksp-control-1
    - ksp-control-2
    - ksp-control-3
    control-plane:
    - ksp-control-1
    - ksp-control-2
    - ksp-control-3
    worker:
    - ksp-control-1
    - ksp-control-2
    - ksp-control-3
  ## 重点注意下面的内容跟示例一致(自建负载均衡时请按实际修改)
  controlPlaneEndpoint:
    ## Internal loadbalancer for apiservers
    internalLoadbalancer: haproxy 
    domain: lb.opsxlab.cn
    address: ""
    port: 6443
 
# 下面的内容保持不变
......

2.2 使用 KubeKey 增加节点

在增加节点之前,我们再确认一下当前集群的节点信息。

代码语言:shell
复制
$ kubectl get nodes -o wide
NAME            STATUS   ROLES                  AGE   VERSION   INTERNAL-IP    EXTERNAL-IP   OS-IMAGE                    KERNEL-VERSION                       CONTAINER-RUNTIME
ksp-control-1   Ready    control-plane,worker   24h   v1.28.8   192.168.9.91   <none>        openEuler 22.03 (LTS-SP3)   5.10.0-182.0.0.95.oe2203sp3.x86_64   containerd://1.7.13

接下来我们执行下面的命令,使用修改后的配置文件将新增的 Control 节点加入集群。

代码语言:shell
复制
export KKZONE=cn
./kk add nodes -f ksp-v341-v1288.yaml

上面的命令执行后,KubeKey 先检查部署 Kubernetes 的依赖及其它配置是否符合要求。通过检查后,系统将提示您确认安装。输入 yes 并按 ENTER 继续部署。

扩容完成需要大约 2~5 分钟左右,具体时间看网速、机器配置、增加的节点数量。

扩容完成后,您应该会在终端上看到类似于下面的输出。

代码语言:bash
复制
......
21:57:35 CST [InternalLoadbalancerModule] Generate haproxy.cfg
21:57:35 CST skipped: [ksp-control-2]
21:57:35 CST skipped: [ksp-control-1]
21:57:35 CST skipped: [ksp-control-1]
21:57:35 CST [InternalLoadbalancerModule] Calculate the MD5 value according to haproxy.cfg
21:57:35 CST skipped: [ksp-control-2]
21:57:35 CST skipped: [ksp-control-1]
21:57:35 CST skipped: [ksp-control-1]
21:57:35 CST [InternalLoadbalancerModule] Generate haproxy manifest
21:57:35 CST skipped: [ksp-control-2]
21:57:35 CST skipped: [ksp-control-1]
21:57:35 CST skipped: [ksp-control-1]
21:57:35 CST [InternalLoadbalancerModule] Update kubelet config
21:57:36 CST stdout: [ksp-control-3]
server: https://lb.opsxlab.cn:6443
21:57:36 CST stdout: [ksp-control-1]
server: https://127.0.0.1:6443
21:57:36 CST stdout: [ksp-control-2]
server: https://lb.opsxlab.cn:6443
21:57:37 CST skipped: [ksp-control-1]
21:57:37 CST success: [ksp-control-3]
21:57:37 CST success: [ksp-control-2]
21:57:37 CST [InternalLoadbalancerModule] Update kube-proxy configmap
21:57:37 CST skipped: [ksp-control-1]
21:57:37 CST [InternalLoadbalancerModule] Update /etc/hosts
21:57:37 CST success: [ksp-control-2]
21:57:37 CST success: [ksp-control-3]
21:57:37 CST success: [ksp-control-1]
21:57:37 CST [ConfigureKubernetesModule] Configure kubernetes
21:57:37 CST success: [ksp-control-1]
21:57:37 CST skipped: [ksp-control-2]
21:57:37 CST skipped: [ksp-control-3]
21:57:37 CST [ChownModule] Chown user $HOME/.kube dir
21:57:38 CST success: [ksp-control-3]
21:57:38 CST success: [ksp-control-2]
21:57:38 CST success: [ksp-control-1]
21:57:38 CST [AutoRenewCertsModule] Generate k8s certs renew script
21:57:39 CST success: [ksp-control-2]
21:57:39 CST success: [ksp-control-3]
21:57:39 CST success: [ksp-control-1]
21:57:39 CST [AutoRenewCertsModule] Generate k8s certs renew service
21:57:40 CST success: [ksp-control-3]
21:57:40 CST success: [ksp-control-2]
21:57:40 CST success: [ksp-control-1]
21:57:40 CST [AutoRenewCertsModule] Generate k8s certs renew timer
21:57:41 CST success: [ksp-control-3]
21:57:41 CST success: [ksp-control-2]
21:57:41 CST success: [ksp-control-1]
21:57:41 CST [AutoRenewCertsModule] Enable k8s certs renew service
21:57:42 CST success: [ksp-control-2]
21:57:42 CST success: [ksp-control-3]
21:57:42 CST success: [ksp-control-1]
21:57:42 CST Pipeline[AddNodesPipeline] execute successfully

3. 扩容后集群状态验证

3.1 KubeSphere 管理控制台验证集群状态

我们打开浏览器访问 Control-1 节点的 IP 地址和端口 30880,登录 KubeSphere 管理控制台的登录页面。

输入默认用户 admin 和默认密码 P@88w0rd,然后点击「登录」。

  • 查看集群节点信息(三个节点
ksp-add-control-clusters-nodes-v341-v128
ksp-add-control-clusters-nodes-v341-v128
  • 查看组件信息
ksp-add-control-clusters-components-v341-v128
ksp-add-control-clusters-components-v341-v128
  • 查看监控信息(三个节点
ksp-add-control-monitor-cluster-overview-v341-v128
ksp-add-control-monitor-cluster-overview-v341-v128

3.2 Kubectl 命令行验证集群状态

  • 查看集群节点信息

在 Control-1 节点运行 kubectl 命令获取 Kubernetes 集群的节点信息。

代码语言:shell
复制
kubectl get nodes -o wide

在输出结果中可以看到,Kubernetes 集群节点已经变成 11个,并详细展示每个节点的名字、状态、角色、存活时间、Kubernetes 版本号、内部 IP、操作系统类型、内核版本和容器运行时等信息。

代码语言:shell
复制
$ kubectl get nodes -o wide
NAME            STATUS   ROLES                  AGE     VERSION   INTERNAL-IP    EXTERNAL-IP   OS-IMAGE                    KERNEL-VERSION                       CONTAINER-RUNTIME
ksp-control-1   Ready    control-plane,worker   24h     v1.28.8   192.168.9.91   <none>        openEuler 22.03 (LTS-SP3)   5.10.0-182.0.0.95.oe2203sp3.x86_64 containerd://1.7.13
ksp-control-2   Ready    control-plane,worker   5m12s   v1.28.8   192.168.9.92   <none>        openEuler 22.03 (LTS-SP3)   5.10.0-182.0.0.95.oe2203sp3.x86_64 containerd://1.7.13
ksp-control-3   Ready    control-plane,worker   5m13s   v1.28.8   192.168.9.93   <none>        openEuler 22.03 (LTS-SP3)   5.10.0-182.0.0.95.oe2203sp3.x86_64 containerd://1.7.13
  • 查看 Pod 列表

输入以下命令获取在 Kubernetes 集群上运行的 Pod 列表,按工作负载在 NODE 上的分布排序。

代码语言:shell
复制
kubectl get pods -o wide -A | sort -k 8

ksp-control-2 为例(输出结果经过整理),输出结果中可以看到, 新增的节点上运行了 7 个必须的基本组件。

代码语言:shell
复制
$ kubectl get pods -o wide -A | sort -k 8
NAMESPACE                      NAME                                   READY   STATUS    RESTARTS        AGE     IP              NODE          NOMINATED NODE   READINESS GATES
kubesphere-monitoring-system   node-exporter-5p6cx                    2/2     Running   0             24m   192.168.9.92   ksp-control-2   <none>           <none>
kube-system                    calico-node-mtsrd                      1/1     Running   0             24m   192.168.9.92   ksp-control-2   <none>           <none>
kube-system                    kube-apiserver-ksp-control-2           1/1     Running   0             24m   192.168.9.92   ksp-control-2   <none>           <none>
kube-system                    kube-controller-manager-ksp-control-2  1/1     Running   0             24m   192.168.9.92   ksp-control-2   <none>           <none>
kube-system                    kube-proxy-ls2cr                       1/1     Running   0             24m   192.168.9.92   ksp-control-2   <none>           <none>
kube-system                    kube-scheduler-ksp-control-2           1/1     Running   0             24m   192.168.9.92   ksp-control-2   <none>           <none>
kube-system                    nodelocaldns-49bk9                     1/1     Running   0             24m   192.168.9.92   ksp-control-2   <none>           <none>
  • 查看新增 Control 节点镜像列表(11 个
代码语言:shell
复制
$ crictl images ls
IMAGE                                                                   TAG                 IMAGE ID            SIZE
registry.cn-beijing.aliyuncs.com/kubesphereio/cni                       v3.27.3             6527a35581401       88.4MB
registry.cn-beijing.aliyuncs.com/kubesphereio/coredns                   1.9.3               5185b96f0becf       14.8MB
registry.cn-beijing.aliyuncs.com/kubesphereio/k8s-dns-node-cache        1.22.20             ff71cd4ea5ae5       30.5MB
registry.cn-beijing.aliyuncs.com/kubesphereio/kube-apiserver            v1.28.8             e70a71eaa5605       34.7MB
registry.cn-beijing.aliyuncs.com/kubesphereio/kube-controller-manager   v1.28.8             e5ae3e4dc6566       33.5MB
registry.cn-beijing.aliyuncs.com/kubesphereio/kube-proxy                v1.28.8             5ce97277076c6       28.1MB
registry.cn-beijing.aliyuncs.com/kubesphereio/kube-rbac-proxy           v0.11.0             29589495df8d9       19.2MB
registry.cn-beijing.aliyuncs.com/kubesphereio/kube-scheduler            v1.28.8             ad3260645145d       18.7MB
registry.cn-beijing.aliyuncs.com/kubesphereio/node-exporter             v1.3.1              1dbe0e9319764       10.3MB
registry.cn-beijing.aliyuncs.com/kubesphereio/node                      v3.27.3             5c6ffd2b2a1d0       116MB
registry.cn-beijing.aliyuncs.com/kubesphereio/pause                     3.9                 e6f1816883972       321kB
  • 查看原有 Control-1 镜像列表(29 个
代码语言:bash
复制
$ crictl images ls
IMAGE                                                                         TAG                 IMAGE ID            SIZE
registry.cn-beijing.aliyuncs.com/kubesphereio/alertmanager                    v0.23.0             ba2b418f427c0       26.5MB
registry.cn-beijing.aliyuncs.com/kubesphereio/cni                             v3.27.3             6527a35581401       88.4MB
registry.cn-beijing.aliyuncs.com/kubesphereio/coredns                         1.9.3               5185b96f0becf       14.8MB
registry.cn-beijing.aliyuncs.com/kubesphereio/defaultbackend-amd64            1.4                 846921f0fe0e5       1.82MB
registry.cn-beijing.aliyuncs.com/kubesphereio/k8s-dns-node-cache              1.22.20             ff71cd4ea5ae5       30.5MB
registry.cn-beijing.aliyuncs.com/kubesphereio/ks-apiserver                    v3.4.1              c486abe6f1cc8       65.8MB
registry.cn-beijing.aliyuncs.com/kubesphereio/ks-console                      v3.4.1              aa81987f764d3       51.7MB
registry.cn-beijing.aliyuncs.com/kubesphereio/ks-controller-manager           v3.4.1              2a2294b6c6af0       50.3MB
registry.cn-beijing.aliyuncs.com/kubesphereio/ks-installer                    v3.4.1              d6ce52546e1c3       156MB
registry.cn-beijing.aliyuncs.com/kubesphereio/kube-apiserver                  v1.28.8             e70a71eaa5605       34.7MB
registry.cn-beijing.aliyuncs.com/kubesphereio/kube-controller-manager         v1.28.8             e5ae3e4dc6566       33.5MB
registry.cn-beijing.aliyuncs.com/kubesphereio/kube-controllers                v3.27.3             3e4fd05c0c1c0       33.4MB
registry.cn-beijing.aliyuncs.com/kubesphereio/kube-proxy                      v1.28.8             5ce97277076c6       28.1MB
registry.cn-beijing.aliyuncs.com/kubesphereio/kube-rbac-proxy                 v0.11.0             29589495df8d9       19.2MB
registry.cn-beijing.aliyuncs.com/kubesphereio/kube-scheduler                  v1.28.8             ad3260645145d       18.7MB
registry.cn-beijing.aliyuncs.com/kubesphereio/kube-state-metrics              v2.6.0              ec6e2d871c544       12MB
registry.cn-beijing.aliyuncs.com/kubesphereio/kubectl                         v1.22.0             30c7baa8e18c0       26.6MB
registry.cn-beijing.aliyuncs.com/kubesphereio/linux-utils                     3.3.0               e88cfb3a763b9       26.9MB
registry.cn-beijing.aliyuncs.com/kubesphereio/node-exporter                   v1.3.1              1dbe0e9319764       10.3MB
registry.cn-beijing.aliyuncs.com/kubesphereio/node                            v3.27.3             5c6ffd2b2a1d0       116MB
registry.cn-beijing.aliyuncs.com/kubesphereio/notification-manager-operator   v2.3.0              7ffe334bf3772       19.3MB
registry.cn-beijing.aliyuncs.com/kubesphereio/notification-manager            v2.3.0              2c35ec9a2c185       21.6MB
registry.cn-beijing.aliyuncs.com/kubesphereio/notification-tenant-sidecar     v3.2.0              4b47c43ec6ab6       14.7MB
registry.cn-beijing.aliyuncs.com/kubesphereio/pause                           3.9                 e6f1816883972       321kB
registry.cn-beijing.aliyuncs.com/kubesphereio/prometheus-config-reloader      v0.55.1             7c63de88523a9       4.84MB
registry.cn-beijing.aliyuncs.com/kubesphereio/prometheus-operator             v0.55.1             b30c215b787f5       14.3MB
registry.cn-beijing.aliyuncs.com/kubesphereio/prometheus                      v2.39.1             6b9895947e9e4       88.5MB
registry.cn-beijing.aliyuncs.com/kubesphereio/provisioner-localpv             3.3.0               739e82fed8b2c       28.8MB
registry.cn-beijing.aliyuncs.com/kubesphereio/snapshot-controller             v4.0.0              f1d8a00ae690f       19MB

至此,我们完成了利用 Kubekey 在现有单节点 Kubernetes 集群中扩容控制节点的全部任务。

重要声明:本文仅为了验证测试 Kubekey 扩容控制节点的能力,文章内容仅供参考,生产环境请勿直接使用

4. 运维自动化

文章中所有操作步骤,已全部编排为自动化脚本,包含以下内容(因篇幅限制,不在此文档中展示):

  • Ansible 自动初始化 K8S 集群节点

运维有术星球会员请到专属代码仓库下载(价值内容,仅星球会员专享)。

以上,就是我今天分享的全部内容。下一期分享的内容还没想好,敬请期待开盲盒

如果你喜欢本文,请分享、收藏、点赞、评论! 请持续关注 @运维有术,及时收看更多好文!

欢迎加入 「知识星球|运维有术」 ,获取更多的 KubeSphere、Kubernetes、云原生运维、自动化运维、AI 大模型等实战技能。未来运维生涯始终有我坐在你的副驾

免责声明:

  • 笔者水平有限,尽管经过多次验证和检查,尽力确保内容的准确性,但仍可能存在疏漏之处。敬请业界专家大佬不吝指教。
  • 本文所述内容仅通过实战环境验证测试,读者可学习、借鉴,但严禁直接用于生产环境由此引发的任何问题,作者概不负责

Get 本文实战视频(请注意,文档视频异步发行,请先关注)

版权声明

  • 所有内容均属于原创,感谢阅读、收藏,转载请联系授权,未经授权不得转载

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • KubeSphere 最佳实战:KubeKey 助力 Kubernetes 扩容控制节点实战指南
    • 1. 前置条件
      • 1.1 部署单节点集群
      • 1.2 操作系统初始化配置
    • 2. 使用 KubeKey 扩容控制节点
      • 2.1 修改集群配置文件
      • 2.2 使用 KubeKey 增加节点
    • 3. 扩容后集群状态验证
      • 3.1 KubeSphere 管理控制台验证集群状态
      • 3.2 Kubectl 命令行验证集群状态
    • 4. 运维自动化
    相关产品与服务
    容器服务
    腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档