kubekey部署k8s集群是基于kubeadm的

生成需要安装的kubernetes版本和可视化版本及安装所需软件:

1. 查看ks支持哪个版本
./kk version --show-supported-k8s
创建kk,根据支持的并且自己想要的版本来生成配置文件
如果需要kubesphere则加上 --with-kubesphere v4.1.3
./kk create config --with-kubernetes v1.30.1 --with-kubesphere v3.4.1
./kk create config --with-kubernetes v1.28.12
#修改配置文件
官方配置示例:https://github.com/kubesphere/kubekey/blob/master/docs/config-example.md
所需依赖
yum install -y tar curl socat conntrack ebtables ipset ipvsadm vim wget
export KKZONE=cn
./kk create cluster -f config-sample.yaml
测试
kubectl create deployment web -r 1 --image=swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginx:1.27.0

2.有时候安装集群报错,先删除后再创建试试
./kk delete cluster -f config-sample.yaml

3.修改安装yaml:

点击查看代码
apiVersion: kubekey.kubesphere.io/v1alpha2
kind: Cluster
metadata:
  name: sample
spec:
  hosts:
  - {name: pm1, address: 10.88.240.11, internalAddress: 10.88.240.11, user: root, password: "123456)"}
  - {name: pw1, address: 10.88.240.12, internalAddress: 10.88.240.12, user: root, password: "123456)"}
  - {name: pw2, address: 10.88.240.13, internalAddress: 10.88.240.13, user: root, password: "123456)"}
  - {name: pw3, address: 10.88.240.14, internalAddress: 10.88.240.14, user: root, password: "123456)"}
  roleGroups:
    etcd:
    - pm1
    control-plane: 
    - pm1
    worker:
    - pw1
    - pw2
    - pw3
    - pw4
  controlPlaneEndpoint:
    ## Internal loadbalancer for apiservers 
    # internalLoadbalancer: haproxy
    domain: lb.kubesphere.local
    address: ""
    port: 6443
  system:
    # The ntp servers of chrony.
    ntpServers:
      - ntp.tencent.com
      - ntp.aliyun.com
      - ntp1.aliyun.com
    timezone: "Asia/Shanghai"
  kubernetes:
    version: v1.30.1
    clusterName: cluster.local
    autoRenewCerts: true
    containerManager: containerd
    proxyMode: ipvs
  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: []

4.升级kubernetes版本:

基于现有的集群创建一个 sample.yaml 配置文件,最好还是保留原有的config-sample.yaml
原有的config-sample.yaml信息最足,sample.yaml还得按配置里的要求进行修改
./kk create config --from-cluster
升级到指定版本
./kk upgrade --with-kubernetes v1.30.1 --with-kubesphere v3.4.1 -f sample.yaml

添加新节点,也建议保留原先的config-sample.yaml来使用,而不是sample.yaml
./kk add nodes -f sample.yaml

5.后续添加证书:

./kk certs check-expiration [(-f | --file) path]

-f to specify the configuration file which was generated for cluster creation. This parameter is not required if it is single node.

./kk certs renew [(-f | --file) path]

-f to specify the configuration file which was generated for cluster creation. This parameter is not required if it is single node.

posted on 2026-05-18 13:31  Warm-Wish  阅读(27)  评论(0)    收藏  举报