kind
kind(Kubernetes in Docker)はローカル環境でKubernetesクラスタを実行するツール。
Dockerコンテナをノードとしてクラスタを構成する。
Kubernetes自体のテストや、開発環境、CIにも利用できる。
公式サイトのクイックスタートに従って、マルチノードのクラスタを構築する
[https://kind.sigs.k8s.io/docs/user/quick-start/:embed:cite]
環境
- M1 Mac mini
- Docker Desktop for Macはインストール済み
インストール
Homebreでインストールする。
$ brew install kind
$ kind version 0.15.0
クラスタ構築
create clusterコマンドでクラスタを作成&実行する、それだけ。
$ kind create cluster
Creating cluster "kind" ...
✓ Ensuring node image (kindest/node:v1.25.0) 🖼
✓ 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
何も設定しないとコントロールプレーン一つのクラスタができる。
$ kubectl get no
NAME STATUS ROLES AGE VERSION
kind-control-plane Ready control-plane 4m49s v1.25.0
コンテナがノードとして起動している。
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
613f6415db46 kindest/node:v1.25.0 "/usr/local/bin/entr…" 5 minutes ago Up 5 minutes 127.0.0.1:50807->6443/tcp kind-control-plane
マルチノード
クラスタの修正はできないっぽいのでさっき作ったクラスタを消す。
$ kind delete cluster
Deleting cluster "kind" ...
yamlで設定ファイルを書くらしい。
```yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: control-plane
- role: worker
- role: worker
```
createの引数に設定ファイルを指定する。
$ kind create cluster --config kind.yaml
Creating cluster "kind" ...
✓ Ensuring node image (kindest/node:v1.25.0) 🖼
✓ Preparing nodes 📦 📦 📦 📦
✓ Configuring the external load balancer ⚖️
✓ Writing configuration 📜
✓ Starting control-plane 🕹️
✓ Installing CNI 🔌
✓ Installing StorageClass 💾
✓ Joining more control-plane nodes 🎮
✓ Joining worker nodes 🚜
Set kubectl context to "kind-kind"
You can now use your cluster with:
kubectl cluster-info --context kind-kind
Have a nice day! 👋
コントロールプレーンとデータプレーンのノードがそれぞれ2台の構成になった。
$ kubectl get no
NAME STATUS ROLES AGE VERSION
kind-control-plane Ready control-plane 85s v1.25.0
kind-control-plane2 Ready control-plane 70s v1.25.0
kind-worker Ready <none> 11s v1.25.0
kind-worker2 Ready <none> 10s v1.25.0
あとがき
楽すぎる、起動も削除も早くて良い。
ブログ書いてて思ったこと。
テーマを一個決めて短くすると良い。長くなったら分割する。投稿のハードルを下げることが大事。
あと内容がシンプルで推敲しやすいので質が上がる。
質と量のいいとこ取りだ。
ホイホイ投稿していきたい。
次
- サンプルアプリのデプロイ
- kubernetesの動作検証