当前位置: 首页 > news >正文

使用kubekey快速搭建k8s集群

项目仓库地址

  • https://github.com/kubesphere/kubekey/

支持的Kubernetes Versions

  • https://github.com/kubesphere/kubekey/blob/master/docs/kubernetes-versions.md

安装

  • 选择自己想要下载的版本
    • https://github.com/kubesphere/kubekey/releases
  • 复制下载链接并下载
    示例:
    wget https://github.com/kubesphere/kubekey/releases/download/v3.1.5/kubekey-v3.1.5-linux-amd64.tar.gz
    
  • 解压到需要安装的位置
    示例:
    tar -xf kubekey-v*-linux-amd64.tar.gz -C /usr/local/bin
    echo "export PATH=$PATH:/usr/local/bin/kk" >> ~/.bashrc
    source ~/.bashrc
    
  • 命令自动补全
    (存疑:执行后没有效果)
    echo "source <(kk completion -t bash)" >> ~/.bashrc
    source ~/.bashrc
    

搭建k8s集群

示例:

  • 生成一个配置文件
    kk create config --name config-cluster-example
    # 会生成一个config-cluster-example.yaml的配置文件
    
  • 编辑配置文件
    vim config-cluster-example.yaml
    
  • 配置文件概述
    apiVersion: kubekey.kubesphere.io/v1alpha2
    kind: Cluster
    metadata:name: config-cluster-example
    spec:hosts: #配置集群的所有node信息,name是node的主机名,会自动把节点主机名改为name的值,address是节点ip,internalAddress是节点内网ip,user和password是登陆节点的用户名和密码,如果配置了ssh密钥登陆,可以删除user和password字段。- {name: node1, address: 172.16.0.2, internalAddress: 172.16.0.2, user: ubuntu, password: "Qcloud@123"}- {name: node2, address: 172.16.0.3, internalAddress: 172.16.0.3}roleGroups: # 指定节点的身份etcd:- node1control-plane: - node1worker:- node1- node2controlPlaneEndpoint:## Internal loadbalancer for apiservers # internalLoadbalancer: haproxydomain: lb.kubesphere.local # apiServer监听的域名,默认即可address: "172.16.0.2" # apiServer监听的ip,需要自己指定port: 6443 # apiServer监听的端口号,默认即可kubernetes:version: v1.23.15 # 需要安装的集群版本,没有需求默认即可clusterName: cluster.localautoRenewCerts: truecontainerManager: dockeretcd:type: kubekeynetwork:plugin: calicokubePodsCIDR: 10.233.64.0/18kubeServiceCIDR: 10.233.0.0/18## multus support. https://github.com/k8snetworkplumbingwg/multus-cnimultusCNI:enabled: falseregistry:privateRegistry: ""namespaceOverride: ""registryMirrors: []insecureRegistries: []addons: []
    
  • 安装必要组件
    # 所有node都需要执行
    apt install -y socat ipset conntrack chrony ipvsadm ebtables
    
  • 创建集群
    kk create cluster -yf config-cluster-example.yaml
    
  • 安装kubectl(已安装则不用再进行安装)
    # 命令自动补全
    echo "source <(kubectl completion bash)" >> ~/.bashrc
    source ~/.bashrc
    

扩展操作

  • 删除集群
    kk delete cluster <clusterName>
    
  • 查看kubekey版本
    kk version
    
  • 更新集群版本
    kk upgrade -y --with-kubernetes <version> <clusterName> 或
    kk upgrade -y -f <config>.yaml # 推荐
    
  • 删除node
    kk delete node <nodeName>
    
  • 添加node
    kk add -y nodes <nodeName>或
    kk add -y nodes -f <config>.yaml # 推荐
    
  • 在worker上可以管理集群
    mkdir -p .kube/config
    scp root@<master>:/etc/kubernetes/admin.conf ~/.kube/config # 从master上拷贝 集群管理员的权限
    echo "export KUBECONFIG=.kube/config/admin.conf" >> .bashrc
    source .bashrc# KubeKey 默认不会启用 kubectl 自动补全功能。
    # 将 completion 脚本添加到你的 ~/.bashrc 文件
    echo "source <(kubectl completion bash)" >> ~/.bashrc
    source ~/.bashrc
    # 将 completion 脚本添加到 /etc/bash_completion.d 目录
    kubectl completion bash >/etc/bash_completion.d/kubect
    
  • 创建一个部署了 KubeSphere 的 Kubernetes 集群 的 配置文件

    例如 --with-kubesphere v3.1.0

    kk create config --with-kubesphere --name <clusterName>
    
  • 创建一个部署了 KubeSphere 的 Kubernetes 集群

    例如 --with-kubesphere v3.1.0

    kk create cluster --with-kubesphere v3.1.0
    
  • 从已有的集群创建配置文件
    kk create config --from-cluster cluster1 -f cluster2.yaml
    
  • 创建容器是指定 container runtime

    可选:docker, crio, containerd and isula

    kk create cluster --container-manager <container_runtime> -f <config>.yaml
    
  • 查看kubekey支持的kubernetes的版本
    kk version --show-supported-k8s
    
  • 查看kubesphere安装
    kubectl apply -f https://github.com/kubesphere/ks-installer/releases/download/v3.4.1/kubesphere-installer.yamlkubectl apply -f https://github.com/kubesphere/ks-installer/releases/download/v3.4.1/cluster-configuration.yaml
    
  • 查看kubesphere删除
    kubectl delete --force -f https://github.com/kubesphere/ks-installer/releases/download/v3.4.1/kubesphere-installer.yamlkubectl delete --force -f https://github.com/kubesphere/ks-installer/releases/download/v3.4.1/cluster-configuration.yaml
    
http://www.lryc.cn/news/427934.html

相关文章:

  • C++——入门基础(上)
  • Spring事务失效
  • Qt QLabel标签制作弹框效果,3s后缓慢自动消失
  • JZ55 二叉树的深度
  • 视频号分销系统搭建教程,源代码+部署上线指南
  • 【python】cryptography库学习
  • 解密!抖音百万粉丝博主三维地图视频都用到了什么GIS数据和技术
  • Python知识点:如何使用Kubernetes与Python进行容器编排
  • Markdown与Word中插入图片的方法及比较
  • Vue3+Vite安装配置tailwindCss
  • 大数据学习-Spark基础入门
  • C语言:链表插入
  • xss 一些例子
  • 基于Docker compose部署Confluence 8.3.4及设置数据持久化存储的总结
  • eNSP 华为交换机生成树协议
  • flutter事件与消息通知
  • Oracle PL/SQL存储过程和函数简单示例
  • 同态加密和SEAL库的介绍(十)CKKS 参数心得 2
  • Debug-021-el-table实现分页多选的效果(切换分页,仍可以保持前一页的选中效果)
  • FPGA开发——DS18B20读取温度并且在数码管上显示
  • 电流测量分流电阻
  • MES系统:智能化排班排产的全面解决方案
  • 50道深度NLP和人工智能领域面试题+答案
  • 最小矩阵宽度(85%用例)C卷(JavaPythonC++Node.jsC语言)
  • STM32数据按字符截取与转换
  • 使用kubeadm快速部署一套K8S集群
  • 【Kotlin】在Kotlin项目中使用AspectJ
  • web实现drag拖拽布局
  • Linux网络编程—listen、accept、connect
  • logback.xml自定义标签节点