- 記事作成日:2022/11/29
情報
名前 | URL |
---|---|
Github | https://github.com/kubernetes-sigs/kind |
公式サイト | https://kind.sigs.k8s.io/ |
デモサイト | |
開発母体 | kubernetes-sigs |
version | v0.17.0 |
言語 | Go |
価格 | 無料 |
ライセンス | Apache-2.0 license |
何ができるもの?
kubernetes in docker
の略で kind
が示す通り、kubernetes における node を Docker コンテナとして起動することで、簡単にローカルで kubrnetes クラスタを作れるツール。
提供機能は以下の通り
- CLI
- メイン機能
- node イメージ
の3種類に分かれてる。
使い方
❯ go install sigs.k8s.io/kind@v0.17.0 go: downloading sigs.k8s.io/kind v0.17.0 go: downloading github.com/spf13/cobra v1.4.0 go: downloading github.com/alessio/shellescape v1.4.1 go: downloading github.com/pelletier/go-toml v1.9.4 go: downloading golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c go: downloading github.com/BurntSushi/toml v1.0.0 go: downloading github.com/evanphx/json-patch/v5 v5.6.0 go: downloading sigs.k8s.io/yaml v1.3.0 go: downloading github.com/google/safetext v0.0.0-20220905092116-b49f7bc46da2 go install sigs.k8s.io/kind@v0.17.0 5.17s user 2.75s system 47% cpu 16.553 total ❯ kind create cluster Creating cluster "kind" ... ✓ Ensuring node image (kindest/node:v1.25.3) 🖼 ✓ 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! 👋 ❯ docker ps | grep kind 10a930c0d861 kindest/node:v1.25.3 "/usr/local/bin/entr…" 6 minutes ago Up 6 minutes 127.0.0.1:51202->6443/tcp kind-control-plane
kind create cluster
を実行すると、ローカルの $HOME/.kube/config
に対して今作成した Cluster のクレデンシャルを書き込む。
kind への接続
❯ kind get clusters kind ❯ kubectl cluster-info kind-kind Kubernetes control plane is running at https://127.0.0.1:51202 CoreDNS is running at https://127.0.0.1:51202/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'. ❯ kubectl get pod -A NAMESPACE NAME READY STATUS RESTARTS AGE kube-system coredns-565d847f94-n4skb 1/1 Running 0 10m kube-system coredns-565d847f94-tpvv4 1/1 Running 0 10m kube-system etcd-kind-control-plane 1/1 Running 0 10m kube-system kindnet-cthhn 1/1 Running 0 10m kube-system kube-apiserver-kind-control-plane 1/1 Running 0 10m kube-system kube-controller-manager-kind-control-plane 1/1 Running 0 10m kube-system kube-proxy-rdhwk 1/1 Running 0 10m kube-system kube-scheduler-kind-control-plane 1/1 Running 0 10m local-path-storage local-path-provisioner-684f458cdd-q4px2 1/1 Running 0 10m ❯ kubectl get node NAME STATUS ROLES AGE VERSION kind-control-plane Ready control-plane 11m v1.25.3
Nginx を起動してみる
❯ kubectl create deployment nginx --image=nginx deployment.apps/nginx created ❯ kubectl get pod NAME READY STATUS RESTARTS AGE nginx-76d6c9b8c-tn59f 1/1 Running 0 20m ❯ kubectl port-forward nginx-76d6c9b8c-tn59f 8000:80 Forwarding from 127.0.0.1:8000 -> 80 Forwarding from [::1]:8000 -> 80
別ターミナル
❯ curl localhost:8000 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> html { color-scheme: light dark; } body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>
Control Plane 3台 / Worker 3台で起動
❯ kind create cluster --name kind-cluster --config <(cat << EOF kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 nodes: - role: control-plane - role: control-plane - role: control-plane - role: worker - role: worker - role: worker EOF ) Creating cluster "kind-cluster" ... ✓ Ensuring node image (kindest/node:v1.25.3) 🖼 ✓ 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-cluster" You can now use your cluster with: kubectl cluster-info --context kind-kind-cluster Thanks for using kind! 😊 kind create cluster --name kind-cluster --config 8.86s user 4.51s system 12% cpu 1:49.68 total ❯ kubectl cluster-info kind-kind-cluster Kubernetes control plane is running at https://127.0.0.1:52247 CoreDNS is running at https://127.0.0.1:52247/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'. ❯ kubectl get node NAME STATUS ROLES AGE VERSION kind-cluster-control-plane Ready control-plane 100s v1.25.3 kind-cluster-control-plane2 Ready control-plane 87s v1.25.3 kind-cluster-control-plane3 Ready control-plane 28s v1.25.3 kind-cluster-worker Ready <none> 22s v1.25.3 kind-cluster-worker2 Ready <none> 22s v1.25.3 kind-cluster-worker3 Ready <none> 22s v1.25.3
kind – configuring-your-kind-cluster
Node バージョンを変えたい時
Releases · kubernetes-sigs/kind
- 1.25: kindest/node:v1.25.3@sha256:f52781bc0d7a19fb6c405c2af83abfeb311f130707a0e219175677e366cc45d1
- 1.24: kindest/node:v1.24.7@sha256:577c630ce8e509131eab1aea12c022190978dd2f745aac5eb1fe65c0807eb315
- 1.23: kindest/node:v1.23.13@sha256:ef453bb7c79f0e3caba88d2067d4196f427794086a7d0df8df4f019d5e336b61
- 1.22: kindest/node:v1.22.15@sha256:7d9708c4b0873f0fe2e171e2b1b7f45ae89482617778c1c875f1053d4cef2e41
- 1.21: kindest/node:v1.21.14@sha256:9d9eb5fb26b4fbc0c6d95fa8c790414f9750dd583f5d7cee45d92e8c26670aa1
- 1.20: kindest/node:v1.20.15@sha256:a32bf55309294120616886b5338f95dd98a2f7231519c7dedcec32ba29699394
- 1.19: kindest/node:v1.19.16@sha256:476cb3269232888437b61deca013832fee41f9f074f9bed79f57e4280f7c48b7
❯ kind create cluster --name kind-cluster --config <(cat << EOF kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 nodes: - role: control-plane image: kindest/node:v1.20.15@sha256:a32bf55309294120616886b5338f95dd98a2f7231519c7dedcec32ba29699394 EOF ) Creating cluster "kind-cluster" ... ✓ Ensuring node image (kindest/node:v1.20.15) 🖼 ✓ Preparing nodes 📦 ✓ Writing configuration 📜 ✓ Starting control-plane 🕹️ ✓ Installing CNI 🔌 ✓ Installing StorageClass 💾 Set kubectl context to "kind-kind-cluster" You can now use your cluster with: kubectl cluster-info --context kind-kind-cluster Have a question, bug, or feature request? Let us know! https://kind.sigs.k8s.io/#community 🙂 kind create cluster --name kind-cluster --config 2.08s user 1.03s system 6% cpu 47.421 total
利用シーン
- ローカルで手軽に kubernetes を動かしたい時
- テストで k8s を使いたい時
登場背景
手軽にローカルで k8s を使いたかったとのこと。
気にすること
特になし。 便利にすぐ使える。