簡 介
kind是另一個Kubernetes SIG專案,但它與minikube有很大區別,它可以將集群遷移到Docker容器中,這與生成虛擬機相比,啟動速度大大加快,簡而言之,kind是一個使用Docker容器節點運行本地Kubernetes集群的工具(CLI),
接下來,我們開始吧!
前期準備
想要順利完成本教程,你需要在本地系統中準備好以下程式:
-
Go
-
需要運行的Docker服務
安 裝
使用以下命令下載和安裝kind二進制檔案:
GO111MODULE=”on” go get sigs.k8s.io/[email protected]
確保kind二進制檔案是存在的
> kind version
kind v0.8.1 go1.14.2 darwin/amd64
現在,我們應該能夠使用kind CLI來啟動一個Kubernetes集群:
Usage:
kind [command]Available Commands:
build Build one of [node-image]
completion Output shell completion code for the specified shell
create Creates one of [cluster]
delete Deletes one of [cluster]
export Exports one of [kubeconfig, logs]
get Gets one of [clusters, nodes, kubeconfig]
help Help about any command
load Loads images into nodes
version Prints the kind CLI version
在本文中,我們將聚焦于create、get和delete命令,
創建一個集群
執行以下命令即可創建一個集群:
kind create cluster
> kind create cluster
Creating cluster "kind" ...
? Ensuring node image (kindest/node:v1.18.2) ??
? 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 Have a nice day! ??
將通過拉取最新的Kubernetes節點(v 1.18.2)來創建一個Kubernetes集群,剛剛我們已經創建了一個v 1.18.2的Kubernetes集群,
在創建集群的程序中如果我們沒有--name引數,那么集群名稱將會默認設定為kind,
創建特定版本的K8S集群
我們可以傳--image引數來部署一個特定版本的Kubernetes集群,
使用的命令為:
kind create cluster --image kindest/node:v1.15.6
Creating cluster "kind" ...
? Ensuring node image (kindest/node:v1.15.6) ??
? 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 Have a nice day! ??
列出部署的集群
輸入命令:kind get clusters
> kind get clusters
kind
kind-1.15.6
這應該列出我們此前創建的兩個不同K8S版本的集群,
為kubectl設定背景關系
創建集群之后,kubectl會指出最近創建的K8S集群,
讓我們來檢查一下所有可用的背景關系,
> kubectl config get-contexts
CURRENT NAME CLUSTER
kind-kind kind-kind
* kind-kind-1.15.6 kind-kind-1.15.6
從輸出中,我們可以得到結論,kubectl背景關系目前已經被設定為最新的集群,即kind-1.15.6,(背景關系名稱是以kind為前綴的)
要將kubectl背景關系設定為版本是1.18.2的kind集群,我們需要進行如下操作:
> kubectl config set-context kind-kind
Context "kind-kind" modified.
要驗證kubectl是否指向正確的集群,我們需要檢查節點:
> kubectl get nodes
NAME STATUS ROLES AGE VERSION
kind-1.18.2-control-plane Ready master 8m20s v1.18.2
洗掉某個集群
要洗掉一個特定的群集,可以在--name引數中把集群名稱傳遞給洗掉命令,
命令為:kind delete cluster --name kind
> kind delete cluster --name kind
Deleting cluster "kind" ...
洗掉所有集群
如果你想一次性洗掉所有集群,請執行:
kind delete clusters –all
> kind delete clusters --all
Deleted clusters: ["kind-1.15.6"]
kind的優勢是什么?
kind(Kubernetes in Docker)是一個基于Docker構建的Kubernetes集群的工具,它經過CNCF認證,并且支持多節點集群,包括高可用集群,并且支持Linux、macOS以及Windows作業系統,操作簡單,學習成本低,非常適合用來在本地搭建基于Kubernetes的開發/測驗環境,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/696.html
標籤:其他
