网络营销推广的主要目标,西安关键词seo,温州网站建设首选龙诚互联,食品品牌网站策划在某些时候可能需要快速的部署一个k8s集群用于测试#xff0c;不想部署复杂的k8s集群环境#xff0c;这个时候我们就可以使用kind来部署一个k8s集群了#xff0c;下面是使用kind部署的过程 一、安装单节点集群 1、下载kind二进制文件
[rootlocalhost knid]# curl -Lo ./kin…在某些时候可能需要快速的部署一个k8s集群用于测试不想部署复杂的k8s集群环境这个时候我们就可以使用kind来部署一个k8s集群了下面是使用kind部署的过程 一、安装单节点集群 1、下载kind二进制文件
[rootlocalhost knid]# curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.17.0/kind-linux-amd64% Total % Received % Xferd Average Speed Time Time Time CurrentDload Upload Total Spent Left Speed
100 97 100 97 0 0 115 0 --:--:-- --:--:-- --:--:-- 1160 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 --:--:-- 1259k2、给下载好的kind添加可执行权限
[rootlocalhost knid]# chmod x kind3、将kind命令放在/usr/local/bin/kind
[rootlocalhost knid]# cp kind /usr/local/bin/kind4、查看kind的版本
[rootlocalhost knid]# kind --version
kind version 0.17.05、使用kind创建集群
[rootlocalhost 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-kindThanks for using kind! 说明上面我们已经安装好了 kind接下来就可以使用 kind 搭建 k8s 集群了 5.1、指定集群名称
# 使用 --name 指定名称
[rootlocalhost ~]# 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-huhuThanks for using kind! 6、默认情况下如果未设置 $KUBECONFIG 环境变量则集群访问配置存储在 ${HOME}/.kube/config 中
[rootlocalhost knid]# ll ${HOME}/.kube/config
-rw-------. 1 root root 5582 9月 25 21:55 /root/.kube/config7、查看kind是否启动完成
[rootlocalhost 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-plane8、查看集群
[rootlocalhost ~]# kind get clusters
kind
huhu9、查看集群信息 9.1、查看集群我们需要进入到 docker 容器里面
# 查看 容器 id
[rootlocalhost ~]# 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 容器里面
[rootlocalhost ~]# docker exec -it d9fa3a93f629 /bin/bash
# 查看节点可以看到是单节点的
rootkind-control-plane:/# kubectl get nodes
NAME STATUS ROLES AGE VERSION
kind-control-plane Ready control-plane 12h v1.25.3
# 查看 pod
rootkind-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 12h10、删除集群 10.1、创建了一个集群使用kind create cluster那么删除同样简单使用
# 删除集群--name如果未指定标志则 kind 将使用默认集群上下文名称kind并删除该集群
[rootlocalhost ~]# kind delete cluster11、删除指定名称的集群
# 删除名称为 huhu 的集群
[rootlocalhost ~]# kind delete cluster --namehuhu
Deleting cluster huhu ...12、使用如下命令创建nginx应用
[rootlocalhost ~]# kubectl run nginx-test --imagenginx:latest13、查看nginx应用是否部署成功
rootkind-control-plane:/# kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx-test 1/1 Running 0 11h二、安装多节点集群 上面我们创建的是单节点的集群默认安装的集群只部署了一个控制节点如果需要部署多节点集群我们可以通过配置文件的方式来创建多个容器。这样就可以达到模拟多个节点的目的并以这些节点来构建一个多节点的 kubernetes 集群
创建多节点 kubernetes 集群配置文件
kind 在创建集群的时候支持通过 --config 参数传递配置文件给 kind配置文件可修改的内容主要有 role 和 节点使用的镜像 1、创建一个 multi-node.yaml 的文件内容如下
[rootlocalhost kind]# cat multi-node.yaml
kind: Cluster
# 一共两个节点一个主节点一个从节点
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane # 主节点
- role: worker # 从节点2、配置文件创建完成后就可以使用下面的命令来完成多节点 Kubernetes 集群搭建
# --config 指定 yaml 文件的路径
[rootlocalhost kind]# kind create cluster --configmulti-node.yaml --namemy-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-cluster1Thanks for using kind! 3、使用 docker ps 就可以看到有两个容器在运行
[rootlocalhost 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-worker4、进入到容器中查看节点信息
[rootlocalhost kind]# docker exec -it ece0ed3760bb /bin/bash
rootmy-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 none 13m v1.25.3
# 成功创建了一个master节点和一个node节点5、删除集群
# 执行后将会删除两个 docker 容器
[rootlocalhost kind]# kind delete cluster --namemy-cluster1[rootlocalhost kind]# docker ps | grep kind