KubeKey安装K8s集群

简介: KubeKey安装K8s

KubeKey安装K8s集群

系统要求

  • 一台或多台运行兼容 deb/rpm 的 Linux 操作系统的计算机,例如 Ubuntu 或 CentOS。
  • 每台机器 2 GB 以上的内存,内存不足时应用会受限制。
  • 用作控制平面节点的计算机上至少有 2 个 CPU。
  • 集群中所有计算机之间具有完全的网络连接。你可以使用公共网络或专用网络。

节点网络配置

root@master:~# cat /etc/netplan/50-cloud-init.yaml
network:
  version: 2
  ethernets:
    ens33:
      dhcp4: false
      addresses:
        - 10.10.0.14/24
      routes:
        - to: default
          via: 10.10.0.254
      nameservers:
        addresses: [114.114.114.114, 8.8.8.8]
root@worker:~# cat /etc/netplan/50-cloud-init.yaml
network:
  version: 2
  ethernets:
    ens33:
      dhcp4: false
      addresses:
        - 10.10.0.18/24
      routes:
        - to: default
          via: 10.10.0.254
      nameservers:
        addresses: [114.114.114.114, 8.8.8.8]

系统依赖

Kubernetes 要求操作系统预装以下依赖:

socat conntrack ipset ebtables chrony ipvsadm

安装系统依赖

apt install socat conntrack ebtables ipset chrony ipvsadm -y

在线安装会自动download依赖包进行安装

KubeKey 已为部分 Linux 发行版制作了预编译的依赖包,可在 iso-latest 获取。 支持的具体发行版与构建方式详见 依赖包管理

一、获取KubeKey

  • 方式一: Release 页面

Release 页面获取对应的二进制文件。

  • 方式二: 执行脚本下载KubeKey最新版本
export KKZONE=cn
curl -sfL https://get-kk.kubesphere.io | SKIP_WEB_INSTALLER=true SKIP_PACKAGE=true sh -
原文件 解压后文件
kubekey-v4.x.x-linux-amd64.tar.gz kk:为 KubeKey 的二进制文件
web-installer.tgz dist:Web 页面资源。 host-check.yaml,kubernetes,kubesphere:任务模板文件。 schema:配置文件。 README.md:安装说明文档。
package.sh 离线安装包的构建脚本。

[!NOTE]

在线安装

二、安装K8s

2.1创建节点配置文件,执行以下命令创建文件

root@master:~# ./kk create inventory -o .
write inventory file to inventory.yaml success.

节点配置文件如下:

root@master:~# cat inventory.yaml
apiVersion: kubekey.kubesphere.io/v1
kind: Inventory
metadata:
  name: default
spec:
  hosts: # your can set all nodes here. or set nodes on special groups.
    master:
      connector:
        type: ssh
        host: 10.10.0.14
        port: 22
        user: root
        password: "000000"
      internal_ipv4: 10.10.0.14
    worker:
      connector:
        type: ssh
        host: 10.10.0.18
        port: 22
        user: root
        password: "000000"
      internal_ipv4: 10.10.0.18
  groups:
    # all kubernetes nodes.
    k8s_cluster:
      groups:
        - kube_control_plane
        - kube_worker
    # control_plane nodes
    kube_control_plane:
      hosts:
        - master
    # worker nodes
    kube_worker:
      hosts:
        - worker
    # etcd nodes when etcd_deployment_type is external
    etcd:
      hosts:
        - master
          #    image_registry:
          #      hosts:
          #        - master
    # nfs nodes for registry storage. and kubernetes nfs storage
#    nfs:
#      hosts:
#        - localhost

[!note]

密码字段字符串需用引号引起来

2.2 创建安装配置文件

root@master:~# ./kk create config --with-kubernetes v1.34 -o .
write config file to config-v1.34.yaml success.
root@master:~# cat config-v1.34.yaml
apiVersion: kubekey.kubesphere.io/v1
kind: Config
spec:
  # If set to "cn", online downloads will prioritize domestic sources when available.
  zone: "cn"
  kubernetes:
    # Specify the Kubernetes version to be installed.
    kube_version: v1.34.3
    # Specify the Helm version to be installed.
    helm_version: v3.18.5
    # Tag for the sandbox (pause) image used by pods.
    sandbox_image:
      tag: "3.10.1"
    control_plane_endpoint:
      # Supported HA types: local, kube_vip, haproxy.
      # If set to local, configure local hostname resolution as follows:
      #   - Control-plane nodes: 127.0.0.1  .kubernetes.control_plane_endpoint.host
      #   - Worker nodes:  .init_kubernetes_node  .kubernetes.control_plane_endpoint.host
      type: local
      # Kube-vip image tag used for static pod deployment (when type is kube_vip).
      kube_vip:
        image:
          tag: v0.7.2
      # HAProxy image tag used for static pod deployment (when type is haproxy).
      haproxy:
        image:
          tag: 2.9.6-alpine
  etcd:
    # Specify the etcd version to be installed.
    etcd_version: v3.6.5
  image_registry:
    # Image registry type to install. Supported: harbor, docker-registry.
    # Leave empty to skip installation (assuming an existing registry is available).
    type: ""
    # auth:
    #   # Address of the private image registry
    #   registry: "dockerhub.kubekey.local"
    # Specify a VIP for image registry high availability. If set, enables HA.
    ha_vip: ""
    # ========== Image Registry - High Availability ==========
    # keepalived image tag for load balancing when multiple registry nodes exist.
    # keepalived_version: 2.0.20
    # ========== Image Registry - Harbor ==========
    # Harbor image tag (only valid if type is harbor).
    #harbor_version: v2.10.2
    # docker-compose binary
    #dockercompose_version: v2.20.3
    # ========== Image Registry - Docker Registry ==========
    # Docker Registry image tag (only valid if type is docker-registry).
    # docker_registry_version: 2.8.3
  cri:
    # Container runtime type. Supported: containerd, docker.
    container_manager: containerd
    # ========== CRI Tool ==========
    # crictl binary version.
    crictl_version: v1.34.0
    # ========== Docker Runtime ==========
    # Docker binary version.
    #docker_version: 25.0.5
    # cridockerd version (required for Kubernetes 1.24+).
    # cridockerd_version: v0.3.21
    # ========== Containerd Runtime ==========
    # containerd binary version (active only when container_manager is containerd).
    # containerd_version: v1.7.13
    # runc binary version (active only when container_manager is containerd).
    # runc_version: v1.1.12
  cni:
    # CNI plugin type. Supported: calico, cilium, flannel, hybridnet, kubeovn, other
    type: calico
    # ========== Multi-CNI ==========
    # Multi-CNI type. Supported: multus, spiderpool, none.
    multi_cni: none
    # ========== Multi-CNI - Multus ==========
    # Image tag for Multus (configure if needed).
    # multus:
    #   image:
    #    tag: v4.2.4
    # ========== Multi-CNI - Spiderpool ==========
    # Spiderpool version (configure if needed).
    # spiderpool_version: v1.1.1
    # ========== Calico CNI ==========
    # Calico version (effective only when type is calico).
    calico_version: v3.31.3
    # ========== Cilium CNI ==========
    # Cilium version (effective only when type is cilium).
    #cilium_version: 1.19.1
    # ========== Flannel CNI ==========
    # Flannel version (effective only when type is flannel).
    #flannel_version: v0.27.4
    # ========== Kube-OVN CNI ==========
    # Kube-OVN version (effective only when type is kubeovn).
    #kubeovn_version: v1.15.0
    # ========== Hybridnet CNI ==========
    # Hybridnet version (effective only when type is hybridnet).
    #hybridnet_version: 0.6.8
  storage_class:
    # ========== Storage Class Configuration ==========
    # ========== Local/OpenEBS Storage Class ==========
    # Local storage class settings.
    local:
      enabled: true   # Enable the local storage class.
      default: true   # Set as the default storage class.
    # openebs/dynamic-localpv-provisioner helm chart version.
    localpv_provisioner_version: 4.4.0
    # ========== NFS Storage Class ==========
    nfs:
      enabled: false  # Enable the NFS storage class.
    # nfs-provisioner Helm chart version.
    #nfs_provisioner_version: 4.0.18
  dns:
    # CoreDNS settings.
    coredns:
      image:
        tag: v1.12.1
    # NodeLocalDNS settings.
    nodelocaldns:
      enabled: true
      image:
        tag: 1.26.4
  # the external images will to add in packages
  image_manifests: []

三、安装Kubernetes

./kk create cluster -i inventory.yaml -c config.yaml

四、启用 kubectl 自动补全

KubeKey 默认不启用 kubectl 自动补全。

前置条件:确保已安装 bash-autocompletion 并正常工作。

# 安装 bash-completion
apt-get install bash-completion

# 将补全脚本添加到 ~/.bashrc
echo 'source <(kubectl completion bash)' >>~/.bashrc

# 将补全脚本添加到 /etc/bash_completion.d 目录 旧版
# 使用新标准目录
kubectl completion bash > /usr/share/bash-completion/completions/kubectl

五、删除集群

[!note]

清理包括网络资源、容器运行时、DNS hosts等配置

./kk delete cluster -i inventory.yaml --all --with-data

六、添加节点

方式一:清单文件

./kk add nodes -i inventory.yaml -c config.yaml

方式二:Add Nodes via Command-Line Flags

  1. Ensure inventory.yaml defines the connection information for the nodes to be added.

    Example:

    spec:
      hosts:
        node1:
          connector:
            type: ssh
            host: 192.168.1.101
            port: 22
            user: root
            password: 123456
        node2:
          connector:
            type: ssh
            host: 192.168.1.102
            port: 22
            user: root
            password: 123456
    
  1. Execute the following command to add nodes and specify their roles:

    ./kk add nodes --control-plane node1 --worker node2 -i inventory.yaml -c config.yaml --override
    
  • --control-plane: Specifies the hostnames to be added as control plane nodes. Multiple nodes are separated by commas.
  • --worker: Specifies the hostnames to be added as worker nodes. Multiple nodes are separated by commas.
  • --etcd: Specifies the hostnames to be added as etcd nodes. Multiple nodes are separated by commas.
  • --override: After successful execution, automatically adds the nodes to the corresponding groups and updates inventory.yaml.
相关文章
|
8天前
|
人工智能 开发工具 iOS开发
Claude Code 新手完全上手指南:安装、国产模型配置与常用命令全解
Claude Code 是一款运行在终端环境中的 AI 编程助手,能够直接在命令行中完成代码生成、项目分析、文件修改、命令执行、Git 管理等开发全流程工作。它最大的特点是**任务驱动、终端原生、轻量高效、多模型兼容**,无需图形界面、不依赖 IDE 插件,能够深度融入开发者日常工作流。
2967 7
|
10天前
|
Shell API 开发工具
Claude Code 快速上手指南(新手友好版)
AI编程工具卷疯啦!Claude Code凭借任务驱动+终端原生的特性,成了开发者的效率搭子。本文从安装、登录、切换国产模型到常用命令,手把手带新手快速上手,全程避坑,30分钟独立用起来。
3068 20
|
23天前
|
人工智能 JSON 供应链
畅用7个月无影 JVS Claw |手把手教你把JVS改造成「科研与产业地理情报可视化大师」
LucianaiB分享零成本畅用JVS Claw教程(学生认证享7个月使用权),并开源GeoMind项目——将JVS改造为科研与产业地理情报可视化AI助手,支持飞书文档解析、地理编码与腾讯地图可视化,助力产业关系图谱构建。
23567 15
畅用7个月无影 JVS Claw |手把手教你把JVS改造成「科研与产业地理情报可视化大师」
|
4天前
|
人工智能 Linux BI
国内用 Claude Code 终于不用翻墙了:一行命令搞定,自动接 DeepSeek
JeecgBoot AI专题研究 一键脚本:Claude Code + JeecgBoot Skills + DeepSeek 全平台接入 一行命令装好 Claude Code + JeecgBoot Skills + DeepSeek 接入,无需翻墙使用 Claude Code,支持 Wind
1953 3
国内用 Claude Code 终于不用翻墙了:一行命令搞定,自动接 DeepSeek
|
10天前
|
人工智能 JSON BI
DeepSeek V4-Pro 接入 Claude Code 完全实战:体验、测试与关键避坑指南
Claude Code 作为当前主流的 AI 编程辅助工具,凭借强大的代码理解、工程执行与自动化能力深受开发者喜爱,但原生模型的使用成本相对较高。为了在保持能力的同时进一步降低开销,不少开发者开始寻找兼容度高、价格更友好的替代模型。DeepSeek V4 系列的发布带来了新的选择,该系列包含 V4-Pro 与 V4-Flash 两款模型,并提供了与 Anthropic 完全兼容的 API 接口,理论上只需简单修改配置,即可让 Claude Code 无缝切换为 DeepSeek 引擎。
2460 3
|
8天前
|
人工智能 安全 开发工具
Claude Code 官方工作原理与使用指南
Claude Code 不是传统代码补全工具,而是 Anthropic 推出的终端 AI 代理,具备代理循环、双驱动架构(模型+工具)、全局项目感知、6 种权限模式等核心能力,本文基于官方文档系统解析其工作原理与高效使用技巧。
1339 0
|
8天前
|
存储 Linux iOS开发
【2026最新】MarkText中文版Markdown编辑器使用图解(附安装包)
MarkText是一款免费开源、跨平台的Markdown编辑器,主打所见即所得实时预览,支持Windows/macOS/Linux。内置数学公式、流程图、代码高亮、多主题及PDF/HTML导出,是Typora的轻量免费替代首选。(239字)