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
相关文章
|
Kubernetes Cloud Native Linux
云原生|kubernetes|kubernetes集群部署神器kubekey的初步使用(centos7下的kubekey使用)
云原生|kubernetes|kubernetes集群部署神器kubekey的初步使用(centos7下的kubekey使用)
1021 1
|
1月前
|
人工智能 运维 监控
阿里云的 Agent Infra 长什么样
分享了团队在 Agent 工程化领域的完整思考与产品实践,从构建、部署到规模化运行,如何用一套 Agent Infra 覆盖智能体的开发-运行-治理-运维-优化全周期。
|
29天前
|
存储 Kubernetes 监控
阿里云容器服务Kubernetes版(ACK)对接使用完全指南
本文提供了一份完整的阿里云容器服务Kubernetes版(ACK)对接使用指南。首先解析ACK托管版、专有版与Serverless版的架构差异与选型策略,帮助用户根据业务场景做出合理决策。随后详细讲解通过控制台和Terraform创建ACK托管集群的完整流程,涵盖网络规划(Terway与Flannel对比、CIDR配置)、节点池管理等关键环节。在应用部署层面,深入介绍Deployment、StatefulSet等核心工作负载的YAML编排实践,并通过Service与ALB Ingress实现服务暴露与七层负载均衡。存储管理部分系统讲解基于CSI的云盘动态存储卷与ossfs 2.0的使用方法。可
|
6月前
|
Kubernetes 应用服务中间件 API
应对 Nginx Ingress 退役,是时候理清这些易混淆的概念了
本文希望提供一种更简单的方式,来理解这些容易混淆的技术概念:Nginx、Ingress、Ingress Controller、Ingress API、Nginx Ingress、Higress、Gateway API。
3293 168
|
1月前
|
人工智能 缓存 监控
构建企业级 AI Agent 工程化实践:从原型到生产环境的跨越
本文深入探讨企业级AI Agent从原型到生产的工程化实践,直面LLM概率性与业务确定性的根本矛盾,提出“LLM负责感知推理、代码保障逻辑执行”的混合架构。系统阐述可观测性、安全护栏、性能优化、数据管理四大工程支柱,并结合IT运维、金融合规等实战场景,提供可落地的LLMOps方法论。
|
1月前
|
运维 监控 Kubernetes
阿里云云原生DevOps:基于ACK构建企业级CI/CD流水线
企业上云后,如何高效地进行应用交付成为核心挑战。本文分享基于阿里云容器服务ACK和云效DevOps平台构建企业级CI/CD流水线的完整实践,涵盖镜像构建、自动部署、灰度发布、安全扫描和成本优化5个核心环节。以一个日活百万的在线教育平台为例,将发布频率从每周1次提升到每天10次,部署成功率从85%提升到99.5%,年节省服务器成本约48万元。
|
3月前
|
自然语言处理 安全 测试技术
大模型+超自动化:实在Agent从“句意理解”到“跨系统闭环执行”的技术链路
本文剖析实在Agent“六层闭环技术架构”,直击企业级智能体落地核心痛点——“认知-执行断层”。通过垂直大模型+全栈超自动化深度融合,实现从自然语言指令到跨系统业务闭环执行的端到端自主化,兼具国产化适配、强合规与高稳定性,为AI工程化提供可落地的技术范式。
|
4月前
|
存储 调度 异构计算
推理平台全景
本次分享介绍了常见的开源推理平台项目: NVIDIA Dynamo, llm-d, Kthena, RoleBasedGroup, OME, AiBrix, KServe
872 8
推理平台全景
|
4月前
|
人工智能 监控 安全
AWS Bedrock 接入 Claude 4.6:近期热门讨论背后的企业落地信号
近期X与GitHub热议AWS Bedrock接入Claude 4.6,焦点已从模型性能转向企业落地难题:认证刷新、配额治理、可观测性与限流。讨论凸显AI工程化分水岭——模型能力趋同,真正瓶颈在于如何无缝融入现有IAM、监控、计费与网络治理体系。