Files
docker_practice/12_orchestration/setup/kind.md
Baohua Yang b44c9acd6c Restruct
2026-02-09 12:56:12 -08:00

91 lines
1.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## Kind - Kubernetes IN Docker
[Kind](https://kind.sigs.k8s.io/) (Kubernetes in Docker) 是一个使用 Docker 容器作为节点运行本地 Kubernetes 集群的工具。主要用于测试 Kubernetes 本身,也非常适合本地开发和 CI 环境。
### 为什么选择 Kind
Kind 相比其他本地集群方案 Minikube有以下显著优势
* **轻量便捷**只要有 Docker 环境即可无需额外虚拟机
* **多集群支持**可以轻松在本地启动多个集群
* **多版本支持**支持指定 Kubernetes 版本进行测试
* **HA 支持**支持模拟高可用集群 Control Plane
### 安装 Kind
Kind 是一个二进制文件并在 PATH 中即可使用以下是不同系统的安装方法
#### macOS
运行以下命令
```bash
brew install kind
```
#### Linux / WindowsWSL2
可以下载二进制文件
```bash
## Linux AMD64
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
```
### 创建集群
最简单的创建方式
```bash
kind create cluster
```
指定集群名称
```bash
kind create cluster --name my-cluster
```
### 与集群交互
Kind 会自动将 kubeconfig 合并到 `~/.kube/config`
```bash
kubectl cluster-info --context kind-kind
kubectl get nodes
```
### 高级用法配置集群
创建一个 `kind-config.yaml` 来定制集群例如映射端口到宿主机
```yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 80
hostPort: 8080
protocol: TCP
- role: worker
- role: worker
```
应用配置
```bash
kind create cluster --config kind-config.yaml
```
### 删除集群
运行以下命令
```bash
kind delete cluster
```