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.
相关实践学习
深入解析Docker容器化技术
Docker是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的Linux机器上,也可以实现虚拟化,容器是完全使用沙箱机制,相互之间不会有任何接口。Docker是世界领先的软件容器平台。开发人员利用Docker可以消除协作编码时“在我的机器上可正常工作”的问题。运维人员利用Docker可以在隔离容器中并行运行和管理应用,获得更好的计算密度。企业利用Docker可以构建敏捷的软件交付管道,以更快的速度、更高的安全性和可靠的信誉为Linux和Windows Server应用发布新功能。 在本套课程中,我们将全面的讲解Docker技术栈,从环境安装到容器、镜像操作以及生产环境如何部署开发的微服务应用。本课程由黑马程序员提供。 &nbsp; &nbsp; 相关的阿里云产品:容器服务 ACK 容器服务 Kubernetes 版(简称 ACK)提供高性能可伸缩的容器应用管理能力,支持企业级容器化应用的全生命周期管理。整合阿里云虚拟化、存储、网络和安全能力,打造云端最佳容器化应用运行环境。 了解产品详情: https://www.aliyun.com/product/kubernetes
相关文章
|
7天前
|
人工智能 运维 监控
阿里云的 Agent Infra 长什么样
分享了团队在 Agent 工程化领域的完整思考与产品实践,从构建、部署到规模化运行,如何用一套 Agent Infra 覆盖智能体的开发-运行-治理-运维-优化全周期。
|
7天前
|
存储 安全 Java
首个 Java Harness Framework 来了丨AgentScope 把 OpenClaw 带到企业分布式场景
本文旨在正式宣告 AgentScope Java 1.1.0 里程碑版本的发布,重点阐述该版本如何从工程实践层面完整落地“Harness Framework”理念。
714 14
|
2天前
|
数据采集 人工智能 安全
别再提“白帽GEO”了——为什么“合规GEO”才是对抗AI投毒的真正底线
本文批判滥用“白帽/黑帽”等过时SEO术语描述生成式引擎优化(GEO)乱象,指出AI投毒、虚假榜单等已逾越技术作弊范畴,触及法律与伦理红线。倡导以“合规GEO”取代理论失焦的旧话术,强调技术、平台、法律三层硬性底线——用对词,方能认清危险;守合规,才是真优化。(239字)
187 120
|
存储 Prometheus 监控
高可用prometheus集群方案选型分享
高可用prometheus集群方案选型分享
7773 2
高可用prometheus集群方案选型分享
|
7天前
|
域名解析 数据采集 运维
Vsping在线Ping:全域网络探测技术与链路稳定性检测解析
Vsping在线Ping是一款轻量级云端网络诊断工具,依托全域分布式节点,支持多地域、多运营商同步Ping探测,无需安装、一键操作。可精准定位延迟、丢包、区域性访问异常等故障,适用于个人自查、远程办公、网站运维及服务器优化,全面提升网络排查效率与稳定性。(239字)
276 0
|
7天前
|
人工智能 API iOS开发
最新版 Claude Code 快速上手指南(新手友好版)
2026年,AI编程工具已经全面进入终端原生、任务驱动、多模型兼容的新时代。Claude Code凭借轻量化、全平台通用、可直接操作文件与执行命令的特性,成为开发者日常效率提升的首选工具。它无需复杂IDE插件,不依赖图形界面,直接在终端运行,能自动规划任务、阅读代码、修改文件、执行脚本,真正融入开发流程。
1311 0
|
虚拟化 Docker 容器
Minikube - Kubernetes本地实验环境
为了方便大家本地开发和体验Kubernetes,社区提供了可以在本机部署的Minikube。本文介绍利用阿里云的镜像地址在Windows/Mac/Linux上来部署和配置Minikube
244470 77
Minikube - Kubernetes本地实验环境
|
SQL 关系型数据库 MySQL
DataX - 全量数据同步工具(1)
DataX - 全量数据同步工具
|
存储 缓存 中间件
高可用之全链路压测
【2月更文挑战第30天】全链路压测是提升系统可用性的关键方法,它模拟真实流量和业务场景在生产环境中测试,确保性能、容量和稳定性。