KubeKey 离线部署 k8s
内网无法连接外网时,需要在联网机器上制作离线包,再复制到内网机器离线安装。
一、所需镜像列表
registry.cn-beijing.aliyuncs.com/kubesphereio/kube-apiserver:v1.25.16
registry.cn-beijing.aliyuncs.com/kubesphereio/kube-controller-manager:v1.25.16
registry.cn-beijing.aliyuncs.com/kubesphereio/kube-proxy:v1.25.16
registry.cn-beijing.aliyuncs.com/kubesphereio/kube-scheduler:v1.25.16
registry.cn-beijing.aliyuncs.com/kubesphereio/pause:3.8
registry.cn-beijing.aliyuncs.com/kubesphereio/coredns:1.9.3
registry.cn-beijing.aliyuncs.com/kubesphereio/cni:v3.27.3
registry.cn-beijing.aliyuncs.com/kubesphereio/kube-controllers:v3.27.3
registry.cn-beijing.aliyuncs.com/kubesphereio/node:v3.27.3
registry.cn-beijing.aliyuncs.com/kubesphereio/pod2daemon-flexvol:v3.23.2
registry.cn-beijing.aliyuncs.com/kubesphereio/k8s-dns-node-cache:1.22.20
二、在联网机器上制作离线包
下载 KubeKey
下载不成功可多试几次:
export KKZONE=cn
curl -sfL https://get-kk.kubesphere.io | VERSION=v3.1.10 sh -
chmod +x kk
cp kk /usr/bin/
配置离线包内容
manifest-sample.yaml 详细说明见官方文档 https://github.com/kubesphere/kubekey/blob/master/docs/manifest-example.md。
vi manifest-sample.yaml # 文件夹中文档含有
制作离线包
export KKZONE=cn
./kk artifact export -m manifest-sample.yaml -o kubesphere.tar.gz
三、将离线包复制到内网机器
scp -r * xx.xx.xx.xx:/root/
四、内网机器离线启动
修改主机名
主机名不要有大写,保持小写:
hostnamectl set-hostname [新主机名]
初始化基础组件(内网机器加入前安装)
# 安装时间同步
apt install -y chrony
systemctl start chronyd
systemctl enable chronyd
# 手动同步一下
timedatectl set-ntp true
chronyc -a makestep
date
apt update
# ubuntu 安装基础依赖
apt install -y socat conntrack ebtables ipset ipvsadm
# 关闭防火墙、iptables、selinux
systemctl stop firewalld && systemctl disable firewalld
systemctl stop iptables && systemctl disable iptables
# 临时关闭 swap
swapoff -a
# 永久关闭 swap:编辑 /etc/fstab 注释掉 swap 一行(修改后需重启)
vim /etc/fstab
free -m
清理已有 kubeconfig,否则会导致其他 node 节点无法使用 kubectl:
rm -rf /root/.kube/config
创建配置文件并修改参数
vi config-cluster-offline.yaml
仓库内置示例
install/kubernetes/rancher/kubekey/config-cluster-offline.yaml:k8s 版本v1.25.16、containerManager: containerd。
五、创建集群
export KKZONE=cn
./kk create cluster -f config-cluster-offline.yaml -a kubesphere.tar.gz --skip-pull-images
六、卸载 KubeSphere 和 Kubernetes
./kk delete cluster -f config-cluster-offline.yaml
平台侧(CubeStudio)的离线镜像准备另见《离线部署》。