1

每天一点 Kubernetes(k8s)--1

环境搭建

如果使用正式的 k8s,那我们可能需要花很多钱买服务器才可以,所以我们选择一个简单易用的,轻量的,可以在本地环境全量试验 k8s 的环境。
网上有很多种,我选择 kind,它满足我以上说的所有要求,使用 docker 运行,其他的 minikube 较重使用虚拟机构建,k3s 合并了很多功能,不能方便的体现 k8s 的各种概念。

下载 kind

官方推荐 4 种方式

1.在macOS / Linux上:

curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/v0.6.0/kind-$(uname)-amd64
chmod +x ./kind
mv ./kind /some-dir-in-your-PATH/kind

2.在Mac上通过Homebrew:

brew install kind

3.在Windows上:

curl.exe -Lo kind-windows-amd64.exe https://github.com/kubernetes-sigs/kind/releases/download/v0.6.0/kind-windows-amd64
Move-Item .\kind-windows-amd64.exe c:\some-dir-in-your-PATH\kind.exe

4.Chocolatey (https://chocolatey.org/packag...

choco install kind

5.使用网页或者下载程序下载
我推荐第 5 种,因为墙的原因,很多时候我们用命令会下载不成功,或者下载回来的,不是正确的程序,我下载回来后一直执行错误,cat kind 一看,原来文件是空的。最后通过浏览器下载回来,移动到 /usr/local/bin 目录,安装成功。

➜  kind kind
kind creates and manages local Kubernetes clusters using Docker container 'nodes'

Usage:
  kind [command]

Available Commands:
  build       Build one of [base-image, node-image]
  completion  Output shell completion code for the specified shell (bash or zsh)
  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

Flags:
  -h, --help              help for kind
      --loglevel string   DEPRECATED: see -v instead
  -q, --quiet             silence all stderr output
  -v, --verbosity int32   info log verbosity
      --version           version for kind

Use "kind [command] --help" for more information about a command.

创建集群

➜  kind kind create cluster --name kind-1
Creating cluster "kind" ...
 ✓ Ensuring node image (kindest/node:v1.16.3) ?
 ✓ Preparing nodes ?
 ✓ Writing configuration ?
 ✓ Starting control-plane ?️
 ✓ Installing CNI ?
 ✓ Installing StorageClass ?
Set kubectl context to "kind-kind-1"
You can now use your cluster with:

kubectl cluster-info --context kind-kind-1

Have a nice day! ?

如果不指定 --name kind-1 默认名称为 kind

获取集群

➜  kind kind get clusters
kind-1

获取所有集群

指定当前集群

➜  kind kubectl cluster-info --context kind-kind-1
Kubernetes master is running at https://127.0.0.1:61230
KubeDNS is running at https://127.0.0.1:61230/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
➜  kind kind delete cluster

删除集群

kind delete cluster --name kind-kind-2
Deleting cluster "kind-kind-2" ...

如果不指定,默认删除 kind-kind


云上码农
1 声望0 粉丝