• kind 安装 k8s 集群


    在某些时候可能需要快速的部署一个k8s集群用于测试,不想部署复杂的k8s集群环境,这个时候我们就可以使用kind来部署一个k8s集群了,下面是使用kind部署的过程
    一、安装单节点集群
    1、下载kind二进制文件

    [root@localhost knid]# curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.17.0/kind-linux-amd64
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100    97  100    97    0     0    115      0 --:--:-- --:--:-- --:--:--   116
      0     0    0     0    0     0      0      0 --:--:--  0:00:02 --:--:--     0
    100 6766k  100 6766k    0     0   793k      0  0:00:08  0:00:08 --:--:-- 1259k
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    2、给下载好的kind添加可执行权限

    [root@localhost knid]# chmod +x kind
    
    • 1

    3、将kind命令放在/usr/local/bin/kind

    [root@localhost knid]# cp kind /usr/local/bin/kind
    
    • 1

    4、查看kind的版本

    [root@localhost knid]# kind --version
    kind version 0.17.0
    
    • 1
    • 2

    5、使用kind创建集群

    [root@localhost knid]# kind create cluster     # 使用此命令创建
    Creating cluster "kind" ...
     ✓ Ensuring node image (kindest/node:v1.25.3) 🖼 
     ✓ Preparing nodes 📦  
     ✓ Writing configuration 📜 
     ✓ Starting control-plane 🕹️ 
     ✓ Installing CNI 🔌 
     ✓ Installing StorageClass 💾 
    Set kubectl context to "kind-kind"
    You can now use your cluster with:
    
    kubectl cluster-info --context kind-kind
    
    Thanks for using kind! 😊
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    说明:上面我们已经安装好了 kind,接下来就可以使用 kind 搭建 k8s 集群了
    5.1、指定集群名称

    # 使用 --name 指定名称
    [root@localhost ~]# kind create cluster --name huhu
    Creating cluster "huhu" ...
     ✓ Ensuring node image (kindest/node:v1.25.3) 🖼 
     ✓ Preparing nodes 📦  
     ✓ Writing configuration 📜 
     ✓ Starting control-plane 🕹️ 
     ✓ Installing CNI 🔌 
     ✓ Installing StorageClass 💾 
    Set kubectl context to "kind-huhu"
    You can now use your cluster with:
    
    kubectl cluster-info --context kind-huhu
    
    Thanks for using kind! 😊
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    6、默认情况下,如果未设置 $KUBECONFIG 环境变量,则集群访问配置存储在 ${HOME}/.kube/config 中

    [root@localhost knid]# ll ${HOME}/.kube/config
    -rw-------. 1 root root 5582 9月  25 21:55 /root/.kube/config
    
    • 1
    • 2

    7、查看kind是否启动完成

    [root@localhost knid]# docker ps -a
    CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS              PORTS                       NAMES
    d9fa3a93f629        kindest/node:v1.25.3   "/usr/local/bin/entr…"   4 minutes ago       Up 3 minutes        127.0.0.1:42737->6443/tcp   kind-control-plane
    
    • 1
    • 2
    • 3

    8、查看集群

    [root@localhost ~]# kind get clusters
    kind
    huhu
    
    • 1
    • 2
    • 3

    9、查看集群信息
    9.1、查看集群我们需要进入到 docker 容器里面

    # 查看 容器 id
    [root@localhost ~]# docker ps |grep kind
    d9fa3a93f629        kindest/node:v1.25.3   "/usr/local/bin/entr…"   12 hours ago        Up 12 hours         127.0.0.1:42737->6443/tcp   kind-control-plane
    
    # 进入到 docker 容器里面
    [root@localhost ~]# docker exec -it d9fa3a93f629 /bin/bash
    # 查看节点,可以看到,是单节点的
    root@kind-control-plane:/# kubectl get nodes
    NAME                 STATUS   ROLES           AGE   VERSION
    kind-control-plane   Ready    control-plane   12h   v1.25.3
    # 查看 pod
    root@kind-control-plane:/# kubectl get pod -n kube-system
    NAME                                         READY   STATUS    RESTARTS   AGE
    coredns-565d847f94-7z8fc                     1/1     Running   0          12h
    coredns-565d847f94-vtlbl                     1/1     Running   0          12h
    etcd-kind-control-plane                      1/1     Running   0          12h
    kindnet-69kkt                                1/1     Running   0          12h
    kube-apiserver-kind-control-plane            1/1     Running   0          12h
    kube-controller-manager-kind-control-plane   1/1     Running   0          12h
    kube-proxy-stbwq                             1/1     Running   0          12h
    kube-scheduler-kind-control-plane            1/1     Running   0          12h
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    10、删除集群
    10.1、创建了一个集群使用​​kind create cluster​​那么删除同样简单,使用

    # 删除集群,--name如果未指定标志,则 kind 将使用默认集群上下文名称kind并删除该集群
    [root@localhost ~]# kind delete cluster
    
    • 1
    • 2

    11、删除指定名称的集群

    # 删除名称为 huhu 的集群
    [root@localhost ~]# kind delete cluster --name=huhu
    Deleting cluster "huhu" ...
    
    • 1
    • 2
    • 3

    12、使用如下命令创建nginx应用

    [root@localhost ~]# kubectl run nginx-test --image=nginx:latest
    
    • 1

    13、查看nginx应用是否部署成功

    root@kind-control-plane:/# kubectl get pod 
    NAME                    READY   STATUS    RESTARTS   AGE
    nginx-test              1/1     Running   0          11h
    
    • 1
    • 2
    • 3

    二、安装多节点集群
    上面我们创建的是单节点的集群,默认安装的集群只部署了一个控制节点,如果需要部署多节点集群,我们可以通过配置文件的方式来创建多个容器。这样就可以达到模拟多个节点的目的,并以这些节点来构建一个多节点的 kubernetes 集群

    创建多节点 kubernetes 集群配置文件

    kind 在创建集群的时候,支持通过 --config 参数传递配置文件给 kind,配置文件可修改的内容主要有 role 和 节点使用的镜像
    1、创建一个 multi-node.yaml 的文件,内容如下

    [root@localhost kind]# cat multi-node.yaml
    kind: Cluster
    # 一共两个节点,一个主节点,一个从节点
    apiVersion: kind.x-k8s.io/v1alpha4
    nodes:
    - role: control-plane  # 主节点
    - role: worker  # 从节点
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    2、配置文件创建完成后,就可以使用下面的命令来完成多节点 Kubernetes 集群搭建

    # --config 指定 yaml 文件的路径
    [root@localhost kind]# kind create cluster --config=multi-node.yaml --name=my-cluster1
    Creating cluster "my-cluster1" ...
     ✓ Ensuring node image (kindest/node:v1.25.3) 🖼 
    ⢄⡱ Preparing nodes 📦 📦  
     ✓ Preparing nodes 📦 📦  
     ✓ Writing configuration 📜 
     ✓ Starting control-plane 🕹️ 
     ✓ Installing CNI 🔌 
     ✓ Installing StorageClass 💾 
     ✓ Joining worker nodes 🚜 
    Set kubectl context to "kind-my-cluster1"
    You can now use your cluster with:
    
    kubectl cluster-info --context kind-my-cluster1
    
    Thanks for using kind! 😊
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    3、使用 docker ps 就可以看到有两个容器在运行

    [root@localhost kind]# docker ps -a
    CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS              PORTS                       NAMES
    ece0ed3760bb        kindest/node:v1.25.3   "/usr/local/bin/entr…"   14 minutes ago      Up 13 minutes       127.0.0.1:38929->6443/tcp   my-cluster1-control-plane
    01a17747a401        kindest/node:v1.25.3   "/usr/local/bin/entr…"   14 minutes ago      Up 13 minutes                                   my-cluster1-worker
    
    • 1
    • 2
    • 3
    • 4

    4、进入到容器中,查看节点信息

    [root@localhost kind]# docker exec -it ece0ed3760bb /bin/bash
    root@my-cluster1-control-plane:/# kubectl get nodes
    NAME                        STATUS   ROLES           AGE   VERSION
    my-cluster1-control-plane   Ready    control-plane   14m   v1.25.3
    my-cluster1-worker          Ready              13m   v1.25.3
    # 成功创建了一个master节点和一个node节点
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    5、删除集群

    # 执行后,将会删除两个 docker 容器 
    [root@localhost kind]# kind delete cluster --name=my-cluster1
    
    [root@localhost kind]# docker ps | grep kind
    
    • 1
    • 2
    • 3
    • 4
  • 相关阅读:
    CF1427F-Boring Card Game【贪心】
    敲黑板|六大问题不搞清楚,一造将无法报名成功
    国内首个智能体生态大会!2024百度万象大会定档5月30日
    STM32Cubemx新建F429基础工程
    Appium+python+unittest搭建UI自动化框架
    无法启动此程序,因为计算机中丢失MSVCR71.dll的详细解决修复方法
    Java9新增特性
    【计算机网络】虚拟路由冗余(VRRP)协议原理与配置
    进程间通信(IPC)
    java spring cloud 工程企业管理软件-综合型项目管理软件-工程系统源码
  • 原文地址:https://blog.csdn.net/ljx1528/article/details/133297195