Unlock Kubernetes Power: Offline Guide Using Kubespray 2.26.0 and Red Hat Linux 9.4_vim

文章目录
  • 1. 简介
  • 2. 要求规格
  • 3. 创建虚拟机模版
  • 3.1 网卡配置
  • 3.2 订阅
  • 3.3 关闭防火墙与selinux
  • 4. 克隆 kubernetes 节点
  • 4.1 bastion01
  • 4.2 kube-master01
  • 4.3 kube-node01
  • 4.4 kube-node02
  • 5. 打快照
  • 6. 配置代理
  • 6.1 主机配置代理
  • 6.2 yum 配置代理
  • 6.3 容器配置代理
  • 7. 配置 DNS (可选)
  • 8. 下载介质
  • 9. 上传介质
  • 10. 部署镜像仓库
  • 11. 推送镜像入库
  • 12. 启动 nginx
  • 13. 配置互信
  • 14. 配置 extract-kubespray.sh
  • 15. 启动部署容器
  • 16. 离线配置
  • 16.1 编写 offline.yml
  • 16.2 配置 containerd.yaml
  • 16.3 部署 offline repo
  • 17. 部署 k8s
  • 18. 配置 kubeconfig
  • 19. 参考

1. 简介

Kubespray 是一个开源项目,旨在通过 Ansible 简化生产就绪的 Kubernetes 集群的部署。它提供了灵活且可定制的框架,支持多种云提供商和本地环境,包括 AWS、Google Cloud Engine、Azure、OpenStack、vSphere 和裸金属环境。这种多样性使用户能够根据需求选择合适的基础设施来运行 Kubernetes 集群。Kubespray 支持创建高可用的 Kubernetes 集群,确保即使在节点故障时,应用程序也能保持正常运行。此外,用户可以选择多种网络插件,如 Calico、Flannel、Canal、Cilium 和 Weave,以便根据具体需求定制网络解决方案。Kubespray 兼容多种流行的 Linux 发行版,包括 CoreOS、Debian、Ubuntu、CentOS/RHEL、Fedora 和 openSUSE,使其适用于广泛的操作系统环境。安装过程相对简单,用户只需安装 Ansible 和所需的 Python 包,然后设置清单并执行 Ansible playbook 来完成 Kubernetes 集群的部署。Kubespray 的 GitHub 页面提供了全面的文档,包括入门指南、部署变量和网络配置等内容,帮助用户快速上手。此外,Kubespray 拥有活跃的社区,通过 Slack 等渠道为用户提供支持。总之,Kubespray 是一个强大的工具,可以高效地在各种环境中部署 Kubernetes 集群,其灵活性和多样性使其成为希望在基础设施中实施 Kubernetes 的组织的理想选择。对于希望实现高可用性和可定制化的用户来说,Kubespray 提供了一种可靠且易于使用的解决方案,是现代云原生应用开发和管理的重要工具。有关更多详细信息和资源,用户可以访问其 GitHub 仓库,以获取最新的更新和社区支持。

2. 要求规格

ip

role

hostname

cpu

mem

disk

description

IP1

bastion

bastion01

8

16G

ssd系统盘:100G

ssd盘:100G

install kubernetes & registry

IP2

control Plane

kube-master01

8

16G

ssd系统盘:100G

kubernetes Components

IP3

worker

kube-node01

16

32G

ssd系统盘:100G

ssd盘:100G

install app

IP4

worker

kube-node02

16

32G

ssd系统盘:100G

ssd盘:100G

install app

3. 创建虚拟机模版

192.168.21.6-rhel-9.6-templ

Unlock Kubernetes Power: Offline Guide Using Kubespray 2.26.0 and Red Hat Linux 9.4_离线_02

Unlock Kubernetes Power: Offline Guide Using Kubespray 2.26.0 and Red Hat Linux 9.4_linux_03

Unlock Kubernetes Power: Offline Guide Using Kubespray 2.26.0 and Red Hat Linux 9.4_容器_04

Unlock Kubernetes Power: Offline Guide Using Kubespray 2.26.0 and Red Hat Linux 9.4_linux_05

Unlock Kubernetes Power: Offline Guide Using Kubespray 2.26.0 and Red Hat Linux 9.4_离线_06

Unlock Kubernetes Power: Offline Guide Using Kubespray 2.26.0 and Red Hat Linux 9.4_kubernetes_07

3.1 网卡配置

cat /etc/NetworkManager/system-connections/ens192.nmconnection
[connection]
id=ens192
type=ethernet
autoconnect-priority=-999
interface-name=ens192
timestamp=1730254410

[ethernet]

[ipv4]
method=manual
address0=192.168.21.6/20,192.168.21.1
dns=8.8.8.8;192.168.21.2


[ipv6]
method=disabled

[proxy]
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
nmcli connection reload && nmcli connection down ens192 && nmcli connection up ens192
  • 1.

3.2 订阅

$ subscription-manager register
Registering to: subscription.rhsm.redhat.com:443/subscription
Username: xxx@xx.com
Password: 
The system has been registered with ID: 4d08e201-e5405c5f5d1
The registered system name is: localhost.localdomain

$ dnf repolist --verbose
Loaded plugins: builddep, changelog, config-manager, copr, debug, debuginfo-install, download, generate_completion_cache, groups-manager, kpatch, needs-restarting, notify-packagekit, playground, product-id, repoclosure, repodiff, repograph, repomanage, reposync, subscription-manager, system-upgrade, uploadprofile
Updating Subscription Management repositories.
DNF version: 4.14.0
cachedir: /var/cache/dnf
Last metadata expiration check: 0:02:53 ago on Wed 30 Oct 2024 02:53:11 PM CST.
Repo-id            : rhel-9-for-x86_64-appstream-rpms
Repo-name          : Red Hat Enterprise Linux 9 for x86_64 - AppStream (RPMs)
Repo-revision      : 1730247754
Repo-updated       : Wed 30 Oct 2024 08:22:33 AM CST
Repo-pkgs          : 19,639
Repo-available-pkgs: 18,927
Repo-size          : 69 G
Repo-baseurl       : https://cdn.redhat.com/content/dist/rhel9/9/x86_64/appstream/os
Repo-expire        : 86,400 second(s) (last: Wed 30 Oct 2024 02:53:10 PM CST)
Repo-filename      : /etc/yum.repos.d/redhat.repo

Repo-id            : rhel-9-for-x86_64-baseos-rpms
Repo-name          : Red Hat Enterprise Linux 9 for x86_64 - BaseOS (RPMs)
Repo-revision      : 1730247532
Repo-updated       : Wed 30 Oct 2024 08:18:52 AM CST
Repo-pkgs          : 7,326
Repo-available-pkgs: 7,326
Repo-size          : 18 G
Repo-baseurl       : https://cdn.redhat.com/content/dist/rhel9/9/x86_64/baseos/os
Repo-expire        : 86,400 second(s) (last: Wed 30 Oct 2024 02:53:11 PM CST)
Repo-filename      : /etc/yum.repos.d/redhat.repo
Total packages: 26,965

$ dnf -y update
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.

3.3 关闭防火墙与selinux

$ systemctl disable firewalld.service
$ setenforce 0 && getenforce
$ sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
  • 1.
  • 2.
  • 3.

关机。

4. 克隆 kubernetes 节点

关机再克隆虚拟机

注意 存储选择 精简模式 : Thin provision,节省空间。

4.1 bastion01

名字:192.168.23.85-rhel-9.4-bastion01

Unlock Kubernetes Power: Offline Guide Using Kubespray 2.26.0 and Red Hat Linux 9.4_kubernetes_08

Unlock Kubernetes Power: Offline Guide Using Kubespray 2.26.0 and Red Hat Linux 9.4_离线_09

ens192 配置192.168.23.85 连接外网下载介质。