用途が違うのでクラスタを別にして色々試したいと思ったので
minikubeを使って、複数のクラスタを構築してみた
関連コマンド
-
クラスタ一覧の確認
minikube profile list
-
クラスタ(PROFILE)作成
minikube start -p [MINIKUBE_PROFILE_NAME]
-
クラスタ プロファイル切り替え(認証変更)
minikube profile [MINIKUBE_PROFILE_NAME]
-
現在のプロファイル確認
minikube profile
-
クラスタの停止
minikube stop [MINIKUBE_PROFILE_NAME]
-
クラスタの起動
minikube start [MINIKUBE_PROFILE_NAME]
-
特定クラスタにSSH
minikube ssh -p [MINIKUBE_PROFILE_NAME]
-
特定クラスタのIPを取得する
minikube ip -p [MINIKUBE_PROFILE_NAME]
-
クラスタの削除
minikube delete -p [MINIKUBE_PROFILE_NAME]
-
kubernetesのversionを指定して作成するコマンド
minikube start -p [MINIKUBE_PROFILE_NAME] --kubernetes-version=v1.XX.XX ※v1.XX.XXにインストールしたversionを指定する
実行例
cluster作成と確認
#作業前のクラスタは1つだけ
@$ minikube profile list
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
| Profile | VM Driver | Runtime | IP | Port | Version | Status | Nodes | Active |
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
| minikube | docker | docker | 192.168.49.2 | 8443 | v1.27.4 | Running | 1 | * |
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
@$
#作成
@$ minikube start -p test
😄 [test] minikube v1.31.2 on Ubuntu 20.04 (amd64)
✨ Automatically selected the docker driver
📌 Using Docker driver with root privileges
👍 Starting control plane node test in cluster test
🚜 Pulling base image ...
🔥 Creating docker container (CPUs=2, Memory=8000MB) ...
🐳 Preparing Kubernetes v1.27.4 on Docker 24.0.4 ...
▪ Generating certificates and keys ...
▪ Booting up control plane ...
▪ Configuring RBAC rules ...
🔗 Configuring bridge CNI (Container Networking Interface) ...
▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
🔎 Verifying Kubernetes components...
🌟 Enabled addons: storage-provisioner, default-storageclass
🏄 Done! kubectl is now configured to use "test" cluster and "default" namespace by default
@$
#Profile が増えていればOK
@$ minikube profile list
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
| Profile | VM Driver | Runtime | IP | Port | Version | Status | Nodes | Active |
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
| minikube | docker | docker | 192.168.49.2 | 8443 | v1.27.4 | Running | 1 | * |
| test | docker | docker | 192.168.58.2 | 8443 | v1.27.4 | Running | 1 | |
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
@$
clusterを停止・起動
#クラスタ停止
@$ minikube stop test
✋ Stopping node "test" ...
🛑 Powering off "test" via SSH ...
🛑 1 node stopped.
@$
#状態確認
@$ minikube stop test
✋ Stopping node "test" ...
🛑 Powering off "test" via SSH ...
🛑 1 node stopped.
@$ minikube profile list
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
| Profile | VM Driver | Runtime | IP | Port | Version | Status | Nodes | Active |
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
| minikube | docker | docker | 192.168.49.2 | 8443 | v1.27.4 | Stopped | 1 | * |
| test | docker | docker | 192.168.58.2 | 8443 | v1.27.4 | Stopped | 1 | |
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
@$
#起動
@$ minikube start test
😄 [test] minikube v1.31.2 on Ubuntu 20.04 (amd64)
✨ Using the docker driver based on existing profile
👍 Starting control plane node test in cluster test
🚜 Pulling base image ...
🔄 Restarting existing docker container for "test" ...
🐳 Preparing Kubernetes v1.27.4 on Docker 24.0.4 ...
🔗 Configuring bridge CNI (Container Networking Interface) ...
🔎 Verifying Kubernetes components...
▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
🌟 Enabled addons: storage-provisioner, default-storageclass
🏄 Done! kubectl is now configured to use "test" cluster and "default" namespace by default
@$
#状態確認
@$
@$ minikube profile list
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
| Profile | VM Driver | Runtime | IP | Port | Version | Status | Nodes | Active |
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
| minikube | docker | docker | 192.168.49.2 | 8443 | v1.27.4 | Stopped | 1 | * |
| test | docker | docker | 192.168.58.2 | 8443 | v1.27.4 | Running | 1 | |
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
@$
プロファイル入れ替え
対象クラスタに対してkubectlで操作できるようにする為には、プロファイルの入れ替えが必要
#プロファイル入れ替え
@$ minikube profile test
✅ minikube profile was successfully set to test
@$
#この結果が対象クラスタのProfileであればOK
@$ minikube profile
test
@$
#一覧でみるとActive の* が入れ替わっていればOK
@$ minikube profile list
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
| Profile | VM Driver | Runtime | IP | Port | Version | Status | Nodes | Active |
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
| minikube | docker | docker | 192.168.49.2 | 8443 | v1.27.4 | Stopped | 1 | |
| test | docker | docker | 192.168.58.2 | 8443 | v1.27.4 | Running | 1 | * |
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
@$
#kubectlコマンドで確認
@$ kubectl config current-context
test
@$
@$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
test Ready control-plane 18m v1.27.4
@$
clusterで色々してみる
#IPを取得
@$ minikube ip -p test
192.168.58.2
@$
#SSHしてみる
@$ minikube ssh -p test
docker@test:~$
docker@test:~$ exit
logout
@$
#削除してみる
@$ minikube delete -p test
🔥 Deleting "test" in docker ...
🔥 Deleting container "test" ...
🔥 Removing /home//.minikube/machines/test ...
💀 Removed all traces of the "test" cluster.
@$
@$ minikube profile list
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
| Profile | VM Driver | Runtime | IP | Port | Version | Status | Nodes | Active |
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
| minikube | docker | docker | 192.168.49.2 | 8443 | v1.27.4 | Stopped | 1 | * |
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
@$
#Kubernetesのversion指定してクラスタ作成
@$ minikube start -p test2 --kubernetes-version=v1.26
😄 [test2] minikube v1.31.2 on Ubuntu 20.04 (amd64)
👉 Using Kubernetes 1.26.7 since patch version was unspecified
✨ Automatically selected the docker driver
📌 Using Docker driver with root privileges
👍 Starting control plane node test2 in cluster test2
🚜 Pulling base image ...
🔥 Creating docker container (CPUs=2, Memory=8000MB) ...
🐳 Preparing Kubernetes v1.26.7 on Docker 24.0.4 ...
▪ Generating certificates and keys ...
▪ Booting up control plane ...
▪ Configuring RBAC rules ...
🔗 Configuring bridge CNI (Container Networking Interface) ...
▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
🔎 Verifying Kubernetes components...
🌟 Enabled addons: storage-provisioner, default-storageclass
❗ /usr/bin/kubectl is version 1.28.1, which may have incompatibilities with Kubernetes 1.26.7.
▪ Want kubectl v1.26.7? Try 'minikube kubectl -- get pods -A'
🏄 Done! kubectl is now configured to use "test2" cluster and "default" namespace by default
@$
@$ minikube profile list
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
| Profile | VM Driver | Runtime | IP | Port | Version | Status | Nodes | Active |
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
| minikube | docker | docker | 192.168.49.2 | 8443 | v1.27.4 | Stopped | 1 | * |
| test | docker | docker | 192.168.58.2 | 8443 | v1.27.4 | Stopped | 1 | |
| test2 | docker | docker | 192.168.67.2 | 8443 | v1.26.7 | Running | 1 | |
|----------|-----------|---------|--------------|------|---------|---------|-------|--------|
@$
#コンテナランタイムに containerd を指定
@$ minikube start -p test2 --container-runtime=containerd
😄 [test2] minikube v1.31.2 on Ubuntu 20.04 (amd64)
✨ Automatically selected the docker driver
📌 Using Docker driver with root privileges
👍 Starting control plane node test2 in cluster test2
🚜 Pulling base image ...
💾 Downloading Kubernetes v1.27.4 preload ...
> preloaded-images-k8s-v18-v1...: 416.44 MiB / 416.44 MiB 100.00% 8.37 Mi
🔥 Creating docker container (CPUs=2, Memory=8000MB) ...
📦 Preparing Kubernetes v1.27.4 on containerd 1.6.21 ...
▪ Generating certificates and keys ...
▪ Booting up control plane ...
▪ Configuring RBAC rules ...
🔗 Configuring CNI (Container Networking Interface) ...
▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
🔎 Verifying Kubernetes components...
🌟 Enabled addons: default-storageclass, storage-provisioner
🏄 Done! kubectl is now configured to use "test2" cluster and "default" namespace by default
@$
@$ minikube profile list
|----------|-----------|------------|--------------|------|---------|---------|-------|--------|
| Profile | VM Driver | Runtime | IP | Port | Version | Status | Nodes | Active |
|----------|-----------|------------|--------------|------|---------|---------|-------|--------|
| minikube | docker | docker | 192.168.49.2 | 8443 | v1.27.4 | Stopped | 1 | |
| test | docker | docker | 192.168.58.2 | 8443 | v1.27.4 | Stopped | 1 | * |
| test2 | docker | containerd | 192.168.67.2 | 8443 | v1.27.4 | Running | 1 | |
|----------|-----------|------------|--------------|------|---------|---------|-------|--------|
@$