基于KubeKey安装Kubernetes集群 v1.23.6
一、准备Linux主机
- 系统环境
| 主机系统 | 最低配置 | 内核版本 |
|---|---|---|
| Ubuntu 22.04.5 LTS | CPU:4 核,内存:8 G,硬盘:120 G | 4.15+ |
| 主机 IP | 主机名 | 角色 |
|---|---|---|
| 192.168.122.11 | master01 | master, etcd,worker |
| 192.168.122.21 | worker01 | worker |
| 192.168.122.22 | worker02 | worker |
| 192.168.122.23 | worker03 | worker |
/var/lib/docker 路径主要用于存储容器数据,在使用和操作过程中数据量会逐渐增加。因此,在生产环境中,建议为 /var/lib/docker 单独挂载一个硬盘
- 节点要求
sudo apt install socat conntrack ebtables ipset ipvsadm -y
二、下载KubeKey
export KKZONE=cn
curl -sfL https://get-kk.kubesphere.io | VERSION=v2.2.0 sh -
chmod +x kk
运行 ./kk version --show-supported-k8s,查看能使用 KubeKey 安装的所有受支持的 Kubernetes 版本
三、配置规划集群
./kk create config --with-kubernetes v1.23.7 [--with-kubesphere v3.2.1]
cat config-sample.yaml
apiVersion: kubekey.kubesphere.io/v1alpha2
kind: Cluster
metadata:
name: sample
spec:
hosts:
- {name: master01, address: 192.168.122.11, internalAddress: 192.168.122.11, user: root, password: "root"}
- {name: worker01, address: 192.168.122.21, internalAddress: 192.168.122.21, user: root, password: "root"}
- {name: worker02, address: 192.168.122.22, internalAddress: 192.168.122.22, user: root, password: "root"}
- {name: worker03, address: 192.168.122.23, internalAddress: 192.168.122.23, user: root, password: "root"}
roleGroups:
etcd:
- master01
control-plane:
- master01
worker:
- worker01
- worker02
- worker03
controlPlaneEndpoint:
## Internal loadbalancer for apiservers
internalLoadbalancer: haproxy
domain: lb.linux.io
address: ""
port: 6443
kubernetes:
version: v1.23.7
clusterName: cluster.local
autoRenewCerts: true
containerManager: docker
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: []
四、创建集群
./kk create cluster -f config-sample.yaml
五、验证集群
~]# kubectl get pod -A
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system calico-kube-controllers-785fcf8454-crhf8 1/1 Running 0 4m11s
kube-system calico-node-4kdjg 0/1 Running 0 4m11s
kube-system calico-node-7h7q8 0/1 Running 0 4m11s
kube-system calico-node-mmtj5 0/1 Running 0 4m11s
kube-system calico-node-x87zv 0/1 Running 3 (56s ago) 4m11s
kube-system coredns-757cd945b-flzk9 1/1 Running 0 4m27s
kube-system coredns-757cd945b-vddxn 1/1 Running 0 4m27s
kube-system haproxy-worker01 1/1 Running 0 4m13s
kube-system haproxy-worker02 1/1 Running 0 4m13s
kube-system haproxy-worker03 1/1 Running 0 4m13s
kube-system kube-apiserver-master01 1/1 Running 0 4m42s
kube-system kube-controller-manager-master01 1/1 Running 0 4m41s
kube-system kube-proxy-5z9tn 1/1 Running 0 4m12s
kube-system kube-proxy-fpkbq 1/1 Running 0 4m12s
kube-system kube-proxy-jqf8m 1/1 Running 0 4m12s
kube-system kube-proxy-mlml4 1/1 Running 0 4m12s
kube-system kube-scheduler-master01 1/1 Running 0 4m42s
kube-system nodelocaldns-9b9qg 1/1 Running 0 4m18s
kube-system nodelocaldns-bpfgk 1/1 Running 0 4m18s
kube-system nodelocaldns-nkn5b 1/1 Running 0 4m27s
kube-system nodelocaldns-pcm96 1/1 Running 0 4m18s
~# kubectl get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
master01 Ready control-plane,master 5m35s v1.23.7 192.168.122.11 <none> Ubuntu 22.04.5 LTS 5.15.0-131-generic docker://20.10.8
worker01 Ready worker 5m10s v1.23.7 192.168.122.21 <none> Ubuntu 22.04.5 LTS 5.15.0-131-generic docker://20.10.22
worker02 Ready worker 5m10s v1.23.7 192.168.122.22 <none> Ubuntu 22.04.5 LTS 5.15.0-131-generic docker://20.10.22
worker03 Ready worker 5m10s v1.23.7 192.168.122.23 <none> Ubuntu 22.04.5 LTS 5.15.0-131-generic docker://20.10.22
六、安装Kuboard-v3
wget https://addons.kuboard.cn/kuboard/kuboard-v3-swr.yaml
kubectl apply -f kuboard-v3-swr.yaml
kubectl get pods -n kuboard -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
kuboard-agent-2-fd7f9458-74x8g 1/1 Running 0 2m14s 10.233.106.3 master01 <none> <none>
kuboard-agent-544c9d9f8d-vsf2h 1/1 Running 0 2m14s 10.233.106.2 master01 <none> <none>
kuboard-etcd-lcxnx 1/1 Running 0 4m52s 192.168.122.11 master01 <none> <none>
kuboard-v3-685dc9c7b8-zfhbg 1/1 Running 0 4m52s 10.233.106.1 master01 <none> <none>
~# kubectl get svc -n kuboard
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kuboard-v3 NodePort 10.233.50.78 <none> 80:30080/TCP,10081:30081/TCP,10081:30081/UDP 5m27s
在浏览器中打开链接 http://your-node-ip-address:30080
输入初始用户名和密码,并登录
- 用户名: admin
- 密码: Kuboard123
通过 Kuboard 安装 Metrics-Server

~# kubectl top nodes
NAME CPU(cores) CPU% MEMORY(bytes) MEMORY%
master01 852m 23% 2808Mi 39%
worker01 398m 11% 1152Mi 16%
worker02 462m 12% 1129Mi 16%
worker03 482m 13% 1246Mi 17%
浙公网安备 33010602011771号