banner
NEWS LETTER

基于KubeKey部署高可用Kubernetes集群

Scroll down

本文作者:丁辉

基于KubeKey部署Kubernetes

节点名称 IP Kubernetes角色
k8s-master-1,KubeKey管理 192.168.1.10 control-plane,etcd,worker
k8s-master-2 192.168.1.20 control-plane,etcd,worker
k8s-master-3 192.168.1.30 control-plane,etcd,worker

基础准备

官方主页

所有节点执行

  1. 创建用户

    1
    useradd -m -s /bin/bash kubekey
  2. 配置用户密码

    根据自己的密码修改 “123456”

    1
    echo "kubekey:123456" | chpasswd
  3. 配置 kubekey 免密使用 sudo 权限

    1
    2
    3
    4
    cat <<EOF | sudo tee /etc/sudoers.d/kubekey
    # User rules for kubekey
    kubekey ALL=(ALL) NOPASSWD: ALL
    EOF
  4. 更改主机名

    • 192.168.1.10

      1
      hostnamectl set-hostname k8s-master-1 && bash
    • 192.168.1.20

      1
      hostnamectl set-hostname k8s-master-2 && bash
    • 192.168.1.30

      1
      hostnamectl set-hostname k8s-master-3 && bash
  5. 编辑 /etc/hosts 文件

    1
    vi /etc/hosts

    添加如下内容

    1
    2
    3
    192.168.1.10 k8s-master-1
    192.168.1.20 k8s-master-2
    192.168.1.30 k8s-master-3
  6. 安装依赖

    • Centos

      1
      yum install conntrack-tools socat -y
    • Ubuntu

      1
      apt install conntrack socat -y

KubeKey管理节点执行

  1. 切换用户

    1
    su - kubekey
  2. 创建密钥

    1
    sudo ssh-keygen -t rsa -N "" -f /root/.ssh/id_rsa -q
  3. 配置免密登录

    1
    2
    3
    sudo ssh-copy-id kubekey@192.168.1.10
    sudo ssh-copy-id kubekey@192.168.1.20
    sudo ssh-copy-id kubekey@192.168.1.30

开始安装 KubeKey

KubeKey-Github-Releases

KubeKey管理节点执行

  1. 下载最新版 KubeKey

    配置国内加速

    1
    export KKZONE=cn
    1
    curl -sfL https://get-kk.kubesphere.io | sh -

    指定版本

    1
    curl -sfL https://get-kk.kubesphere.io | VERSION=v3.0.13 sh -
  2. kk 添加可执行权限

    1
    2
    sudo chmod +x kk
    sudo mv kk /usr/local/bin/
  3. 生成配置文件

    1
    kk create config -f kubesphere.yaml

    安装 Kubesphere 指定参数

    Kubesphere-Github-Releases

    1
    --with-kubesphere v3.4.1

    修改如下内容

    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
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    apiVersion: kubekey.kubesphere.io/v1alpha2
    kind: Cluster
    metadata:
    name: sample
    spec:
    hosts:
    - {name: k8s-master-1, address: 192.168.100.10, internalAddress: 192.168.100.10, user: kubekey, password: "123456"}
    - {name: k8s-master-2, address: 192.168.100.20, internalAddress: 192.168.100.20, user: kubekey, password: "123456"}
    - {name: k8s-master-3, address: 192.168.100.30, internalAddress: 192.168.100.30, user: kubekey, password: "123456"}
    roleGroups:
    etcd:
    - k8s-master-1
    - k8s-master-2
    - k8s-master-3
    control-plane:
    - k8s-master-1
    - k8s-master-2
    - k8s-master-3
    worker:
    - k8s-master-1
    - k8s-master-2
    - k8s-master-3
    controlPlaneEndpoint:
    # 启用内置的 HAProxy 负载均衡器
    internalLoadbalancer: haproxy
    domain: lb.kubesphere.local
    address: ""
    port: 6443
    kubernetes:
    # 指定 Kubernetes 版本, 可使用 kk version --show-supported-k8s 命令查询当前 KubeKey 支持的版本
    version: v1.23.10
    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
    multusCNI:
    enabled: false
    registry:
    privateRegistry: ""
    namespaceOverride: ""
    registryMirrors: []
    insecureRegistries: []
    addons: []

开始安装 Kubernetes

1
kk create cluster -f kubesphere.yaml -y

扩容节点

1
kk add nodes -f kubesphere.yaml -y

卸载集群

1
kk delete cluster -f kubesphere.yaml

I'm so cute. Please give me money.

其他文章
cover
Ingress问题记录
  • 70/01/01
  • 00:00
  • Kubernetes-网关
cover
基于KubeKey快速部署单机Kubernetes
  • 70/01/01
  • 00:00
  • Kubernetes-部署文档
目录导航 置顶
  1. 1. 基于KubeKey部署Kubernetes
    1. 1.1. 基础准备
      1. 1.1.1. 所有节点执行
      2. 1.1.2. KubeKey管理节点执行
    2. 1.2. 开始安装 KubeKey
      1. 1.2.1. KubeKey管理节点执行
    3. 1.3. 开始安装 Kubernetes
    4. 1.4. 卸载集群
请输入关键词进行搜索