kind を使って Kubernetes 環境を構築してみた

◆ Live配信スケジュール ◆
サイオステクノロジーでは、Microsoft MVPの武井による「わかりみの深いシリーズ」など、定期的なLive配信を行っています。
⇒ 詳細スケジュールはこちらから
⇒ 見逃してしまった方はYoutubeチャンネルをご覧ください
【5/21開催】Azure OpenAI ServiceによるRAG実装ガイドを公開しました
生成AIを活用したユースケースで最も一番熱いと言われているRAGの実装ガイドを公開しました。そのガイドの紹介をおこなうイベントです!!
https://tech-lab.connpass.com/event/315703/

こんにちは。サイオステクノロジー OSS サポート担当 Y です。

今回は、kind というツールを使ってシングルノード構成の Kubernetes 環境を構築してみました。(※以下の内容は CentOS 7.6/Docker v19.03.5/kind v0.7.0/Kubernetes v1.17.0 にて検証しています。)

■はじめに

最近は Kubernetes を本番利用する事例の情報も増えてきており、Kubernetes に触れる機会が多い方、新しいプロジェクトで Kubernetes に触れることになった方も多いのではないでしょうか。

マネージドサービス等も充実している Kubernetes ですが、今回は Kubernetes の検証や学習に便利な kind というツールを使って Kubernetes 環境を構築してみました。

■Docker のインストール

kind は Docker を利用するため、まずは Docker をインストールします。詳細は割愛しますが、Get Docker Engine – Community for CentOS を参考にインストールします。

[root@centos7 kind-cluster]# docker version
Client: Docker Engine - Community
 Version:           19.03.5
 API version:       1.40
 Go version:        go1.12.12
 Git commit:        633a0ea
 Built:             Wed Nov 13 07:25:41 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.5
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.12
  Git commit:       633a0ea
  Built:            Wed Nov 13 07:24:18 2019
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.10
  GitCommit:        b34a5c8af56e510852c35414db4c1f4fa6172339
 runc:
  Version:          1.0.0-rc8+dev
  GitCommit:        3e425f80a8c931f88e6d94a8c831b9d5aa481657
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683
[root@centos7 kind-cluster]# 

■kubectl のインストール

次に、Kubernetes 用の CLI ツールである kubectl をインストールします。Install and Set Up kubectl の記載に従い、インストールします。

[root@centos7 kind-cluster]# curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.17.0/bin/linux/amd64/kubectl
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 41.4M  100 41.4M    0     0  1544k      0  0:00:27  0:00:27 --:--:--  952k
[root@centos7 kind-cluster]# 
[root@centos7 kind-cluster]# chmod +x ./kubectl
[root@centos7 kind-cluster]# 
[root@centos7 kind-cluster]# mv ./kubectl /usr/local/bin/
[root@centos7 kind-cluster]# 
[root@centos7 kind-cluster]# ls -l /usr/local/bin/kubectl 
-rwxr-xr-x 1 root root 43495424  3月  5 16:33 /usr/local/bin/kubectl
[root@centos7 kind-cluster]# 
[root@centos7 kind-cluster]# kubectl version
Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.0", GitCommit:"70132b0f130acc0bed193d9ba59dd186f0e634cf", GitTreeState:"clean", BuildDate:"2019-12-07T21:20:10Z", GoVersion:"go1.13.4", Compiler:"gc", Platform:"linux/amd64"}
The connection to the server localhost:8080 was refused - did you specify the right host or port?
[root@centos7 kind-cluster]# 

■kind のインストール

最後に、kind のインストールです。Installation and usage の記載に従い、インストールします。

[root@centos7 kind-cluster]# curl -Lo ./kind "https://github.com/kubernetes-sigs/kind/releases/download/v0.7.0/kind-$(uname)-amd64"
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   607  100   607    0     0   1353      0 --:--:-- --:--:-- --:--:--  1351
100 9136k  100 9136k    0     0   121k      0  0:01:15  0:01:15 --:--:--  156k
[root@centos7 kind-cluster]# 
[root@centos7 kind-cluster]# 
[root@centos7 kind-cluster]# chmod +x ./kind
[root@centos7 kind-cluster]# 
[root@centos7 kind-cluster]# mv ./kind /usr/local/bin/
[root@centos7 kind-cluster]# 
[root@centos7 kind-cluster]# ls -l /usr/local/bin/kind 
-rwxr-xr-x 1 root root 9355777  2月 21 12:02 /usr/local/bin/kind
[root@centos7 kind-cluster]# 
[root@centos7 kind-cluster]# kind version
kind v0.7.0 go1.13.6 linux/amd64
[root@centos7 kind-cluster]# 

■Kubernetes 起動

それではさっそく、kind を使って Kubernetes を起動してみます。Kubernetes を起動する場合は “kind create cluster” コマンドを実行します。

[root@centos7 kind-cluster]# kind create cluster
Creating cluster "kind" ...
 ✓ Ensuring node image (kindest/node:v1.17.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

Have a question, bug, or feature request? Let us know! https://kind.sigs.k8s.io/#community 🙂
[root@centos7 kind-cluster]# 

上記の様にコマンドを一つ実行するだけで Kubernetes が起動しました。

因みに、kind で構築される Kubernetes は Docker 上でコンテナとして動作しているので、docker ps コマンドで当該コンテナを確認することができます。

[root@centos7 kind-cluster]# docker ps
CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS              PORTS                       NAMES
94a5bd32e6cf        kindest/node:v1.17.0   "/usr/local/bin/entr…"   3 minutes ago       Up 3 minutes        127.0.0.1:32768->6443/tcp   kind-control-plane
[root@centos7 kind-cluster]# 

Kubernetes 起動後、kubectl コマンドで当該 Kubernetes を操作するために、以下コマンドで kubeconfig を設定します。

[root@centos7 kind-cluster]# kubectl cluster-info --context kind-kind
Kubernetes master is running at https://127.0.0.1:32768
KubeDNS is running at https://127.0.0.1:32768/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
[root@centos7 kind-cluster]# 

上記コマンド実行後、kubectl node コマンドで Kubernetes が起動していることを確認します。

[root@centos7 kind-cluster]# kubectl get node
NAME                 STATUS   ROLES    AGE     VERSION
kind-control-plane   Ready    master   5m18s   v1.17.0
[root@centos7 kind-cluster]# 

kind で作成した Kubernetes に接続できることが確認できました。

■Kubernetes 停止 (削除)

kind で作成した Kubernetes を削除する場合は、”kind delete cluster” コマンドを実行します。

[root@centos7 kind-cluster]# kind delete cluster
Deleting cluster "kind" ...
[root@centos7 kind-cluster]# 
[root@centos7 kind-cluster]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
[root@centos7 kind-cluster]# 
[root@centos7 kind-cluster]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
[root@centos7 kind-cluster]# 

■まとめ

今回は、kind というツールを使って Kubernetes 環境を構築してみました。Kubernetes の構築や削除がコマンド一つで簡単に実行できるので、Kubernetes の検証等にとても便利なツールだと思います。

今回は単一ノード (Master 1台構成) の Kubernetes を構築しましたが、次回は kind を使った複数ノード構成の Kubernetes クラスタの構築を検証してみようと思います。

アバター画像
About サイオステクノロジーの中の人 41 Articles
サイオステクノロジーで働く中の人です。
ご覧いただきありがとうございます! この投稿はお役に立ちましたか?

役に立った 役に立たなかった

1人がこの投稿は役に立ったと言っています。


ご覧いただきありがとうございます。
ブログの最新情報はSNSでも発信しております。
ぜひTwitterのフォロー&Facebookページにいいねをお願い致します!



>> 雑誌等の執筆依頼を受付しております。
   ご希望の方はお気軽にお問い合わせください!

Be the first to comment

Leave a Reply

Your email address will not be published.


*


質問はこちら 閉じる