Kind最小化安装单机版Kubernetes

铭老师: 在 docker 容器中运行Docker, 模拟出kubernetes 集群, 可以在单机实现模拟和学习 , 适合学习和练习;
本次使用版本为 1.15
直接使用dind-cluster-v1.15.sh 启动集群;

学生1: 等一哈! 不要这样... kubeadm-dind-cluster 已经停止维护2年多了, 没有使用和学习的意义了
现在的替代工具是 kind;
铭老师: 好吧!
年轻人不讲武德吗?
给你看看老夫的实力:
Kind 来了:
https://kind.sigs.k8s.io/docs/user/quick-start/#installation

1. kind 简介

google-kind-logo.png

kind 全称 是 kubernetes in docker ,把 kubernetes 控制面的组件全部运行在一个docker 容器中,在本地通过 127.0.0.1 进行通信。
kind 使用 Docker 容器作为 Nodes,在本地创建和运行 Kubernetes 群集的工具。适用于在本地模拟创建 Kubernetes 群集环境进行。
这种玩法只能在本地体验, 不可用于生产环境,特别适用于新人在本地体验、开发 kubernetes 相关组件时在本地进行调试等,如开始 operator 时可以在 kind 进行调试 。

2. kind 架构

kind 官方架构图如下,它将 docker 容器作为 kubernetes 的 "node",并在该 "node" 中安装 kubernetes 组件,包括一个或者多个 Control Plane 和 一个或者多个 Work nodes。这就解决了在本机运行多个 node 的问题,而不需要虚拟化。


kind-arc.png

2. 安装(install@2021-03-01)

macOS (homebrew):

brew install kind

囧了,

^C
Warning: You are using macOS 10.12.
We (and Apple) do not provide support for this old version.
You will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrew's GitHub,
Twitter or any other official channels. You are responsible for resolving
any issues you experience while you are running this
old version.

Error: kind: no bottle available!
You can try to install from source with:
  brew install --build-from-source kind
Please note building from source is unsupported. You will encounter build
failures with some formulae. If you experience any issues please create pull
requests instead of asking for help on Homebrew's GitHub, Twitter or any other
official channels.

回家换高版本mac 测试了, 离线下个linux版的包回去安装;
只有7M 大, 还好~
到家了,brew 安装了最新版

kind version
kind v0.10.0 go1.15.7 darwin/amd64

Linux:

curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.9.0/kind-linux-amd64
chmod +x ./kind
mv ./kind /usr/local/bin/kind

3. 创建群集

kind create cluster
create cluster
Creating cluster "kind" ...
✓ Ensuring node image (kindest/node:v1.20.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! 👋

先瞟一眼帮助文档

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

Usage:
  kind [command]

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

可以看出支持3种类型的命令,cluster 相关、image 相关、通用命令 。

cluster 相关的有 create, delete 等,主要用于创建和删除 kubernetes 集群。
image 相关的有 build, load 等,主要用于本地调试时,本地可以 build镜像直接load 到集群中,而不需要推送到镜像仓库再通过集群去 pull 。
通用命令如 get ,version 等。

docker ps 查看下

docker ps
CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS              PORTS                       NAMES
dd3cabf73d50        kindest/node:v1.20.2   "/usr/local/bin/entr…"   2 minutes ago       Up 2 minutes        127.0.0.1:56620->6443/tcp   kind-control-plane

kubectl 看下集群信息

kind get clusters
kind

kubectl cluster-info --context kind-kind

Kubernetes master is running at https://127.0.0.1:56620
KubeDNS is running at https://127.0.0.1:56620/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

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

看下活动监视器内存占用, com.docker.hyperkit 整体占用3.69G, 还可以;

查看网络

➜  ~ docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
9e53ec439da9           bridge               bridge                    local
6b803cee6eab           host                 host                        local
712feaf75c41           kind                 bridge                    local
ee33dcd8ff07           none                 null                         local

虚拟机到node容器使用了docker的bridge网络(kind网桥)

默认的群集名称为kind,可以使用参数--name指定创建的群集的名称,可以创建多个群集:

kind create cluster --name kind-2

指定 node 镜像版本创建群集

# default
kind create cluster --image kindest/node:latest
# 1.20.2
kind create cluster --image kindest/node:v1.20.2

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容