使用kubekey搭建kubernetes环境
编辑日期 | 操作 | 编辑者 |
---|---|---|
2024.02.26 | 文档修改 | 万雨 |
裸机操作系统:centos-7.6
集群版本:v1.26.3
1,下载工具
cd ~
mkdir kubekey
cd kubekey/
# 选择中文区下载(访问 GitHub 受限时使用)
# 服务器在国区一定要执行下面的命令,否则大概率会卡在下载工具资源的步骤
export KKZONE=cn
# 执行下载命令,获取最新版的 kk(受限于网络,有时需要执行多次)(官方的)
curl -sfL https://get-kk.kubesphere.io | sh -
# 如果执行上面的命令,因为防火墙的原因,多次失败,可以使用下面的杭州的阿里云OSS仓库的地址
# curl -sfL https://linkee-public.oss-cn-hangzhou.aliyuncs.com/k8s/kubesphere/downloadKubekey.sh | sh -
# 查看当前支持的版本列表
./kk version --show-supported-k8s
# 选择其中的一个k8s集群版本部署(其中的v1.26.3,一定要填写自己的系统支持的版本)
./kk create config --with-kubernetes v1.26.3
2,信息配置
直接在 /root/kubekey中,找到config-sample.yaml文件修改其中的【hosts、roleGroups】信息
apiVersion: kubekey.kubesphere.io/v1alpha2
kind: Cluster
metadata:
name: sample
spec:
hosts:
- {name: master1, address: 10.0.4.12, internalAddress: 10.0.4.12, user: root, password: "password"}
- {name: node1, address: 10.0.12.2, internalAddress: 10.0.12.2, user: root, password: "password"}
- {name: node2, address: 10.0.4.15, internalAddress: 10.0.4.15, user: root, password: "password"}
- {name: node3, address: 10.0.4.17, internalAddress: 10.0.4.17, user: root, password: "password"}
roleGroups:
etcd:
- master1
control-plane:
- master1
worker:
- node1
- node2
- node3
controlPlaneEndpoint:
## Internal loadbalancer for apiservers
# internalLoadbalancer: haproxy
domain: lb.kubesphere.local
address: ""
port: 6443
kubernetes:
version: v1.26.3
clusterName: cluster.local
autoRenewCerts: true
containerManager: containerd
etcd:
type: kubekey
network:
plugin: calico
kubePodsCIDR: 10.233.64.0/18
kubeServiceCIDR: 10.233.0.0/18
## multus support. https://github.com/k8snetworkplumbingwg/multus-cni
multusCNI:
enabled: false
registry:
privateRegistry: ""
namespaceOverride: ""
registryMirrors: []
insecureRegistries: []
addons: []
3,集群搭建启动
./kk create cluster -f config-sample.yaml
搭建完成,可以在master节点执行【kubectl get pod -A 】命令查看相关k8s运行
参考链接:
探究未知是最大乐趣