2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Minikubeであれやりたいときのtips

Posted at

はじめに

「Minikubeで〇〇したい」を集めたTipsです。
minikube v1.17.1で確認しました。

Minikubeで〇〇やりたい

NodeのCPU/Memoryを設定したい

minikube start --cpus 2 --memory 2G

VMじゃなくてdockerでNodeを起動したい

minikube start --driver docker

実はdriverはいろいろ選ぶことができます。
virtualbox, vmwarefusion, kvm2, vmware, none, docker, podman (experimental), ssh

ローカルのコンテナイメージを使いたい

「いちいちContainer Registryにpushして疎通するの面倒くさい!」という時にお勧めです。

eval $(minikube docker-env)

上記コマンド実行後にdocker buildすると、minikubeのNode上にイメージがよしなにされます。
ただしlatest以外のタグを利用してください。latestを指定すると外部を参照しに行ってErrImagePullになります。

複数Nodeのクラスタを作りたい

実はMulti-Nodeクラスタも作れます。
これでTaintやNodeSelector、Pod (Anti) Affinityの確認もできます。

minikube start --nodes 3

構築結果

$ kubectl get nodes
NAME           STATUS   ROLES                  AGE   VERSION
minikube       Ready    control-plane,master   76s   v1.20.2
minikube-m02   Ready    <none>                 42s   v1.20.2
minikube-m03   Ready    <none>                 19s   v1.20.2

Kubernetesのバージョンを指定したい

minikube start --kubernetes-version v1.20.2

type: LoadbalancerなServiceを使いたい

Minikubeのクラスタでtype: LoadBalancerなService Resourceを作成しても、通常はEXTERNAL-IPはPendingになってしまいますが、サブコマンドのtunnelで解決できます。

type: LoadBalancerなServiceとそれに紐づくDeploymentの作成

$ kubectl create deployment hello-node --image=k8s.gcr.io/echoserver:1.4
deployment.apps/hello-node created

$ kubectl expose deployment hello-node --type=LoadBalancer --port=8080
service/hello-node exposed

$ kubectl get svc
NAME         TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
hello-node   LoadBalancer   10.105.111.30   <pending>     8080:30427/TCP   5s
kubernetes   ClusterIP      10.96.0.1       <none>        443/TCP          5m20s

別ターミナルで`minikube tunnelを実行

$ minikube tunnel
Status:	
	machine: minikube
	pid: 23411
	route: 10.96.0.0/12 -> 192.168.49.2
	minikube: Running
	services: [hello-node]
    errors: 
		minikube: no errors
		router: no errors
		loadbalancer emulator: no errors

ServiceのEXTERNAL-IPを確認

gashirar:~$ kubectl get svc
NAME         TYPE           CLUSTER-IP      EXTERNAL-IP     PORT(S)          AGE
hello-node   LoadBalancer   10.105.111.30   10.105.111.30   8080:30427/TCP   3m31s
kubernetes   ClusterIP      10.96.0.1       <none>          443/TCP          8m46s

疎通

$ curl 10.105.111.30:8080
CLIENT VALUES:
client_address=192.168.49.2
command=GET
real path=/
query=nil
request_version=1.1
request_uri=http://10.105.111.30:8080/

SERVER VALUES:
server_version=nginx: 1.10.0 - lua: 10001

HEADERS RECEIVED:
accept=*/*
host=10.105.111.30:8080
user-agent=curl/7.68.0
BODY:
-no body in request-

Nodeの中に入りたい

minikube ssh

kubeletプロセスの確認もできます。

$ minikube ssh
docker@minikube:~$ sudo systemctl status kubelet
● kubelet.service - kubelet: The Kubernetes Node Agent
     Loaded: loaded (/lib/systemd/system/kubelet.service; disabled; vendor preset: enabled)
    Drop-In: /etc/systemd/system/kubelet.service.d
             └─10-kubeadm.conf
     Active: active (running) since Tue 2021-02-09 12:02:22 UTC; 20min ago
       Docs: http://kubernetes.io/docs/
   Main PID: 2395 (kubelet)
      Tasks: 21 (limit: 23919)
     Memory: 51.6M
     CGroup: /docker/3914f62704ff9cbd7ea263df7287ac734d30983a5bcf9f1b5127825434093f64/system.slice/kubelet.service
             └─2395 /var/lib/minikube/binaries/v1.20.2/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --config=/var/lib/kubelet/config.yaml --container-runtime=docker --hostna
me-override=minikube --kubeconfig=/etc/kubernetes/kubelet.conf --network-plugin=cni --node-ip=192.168.49.2

Proxy環境下で実行したい

TBD(構築はできたので後で手順をまとめます)

metrics-serverを導入したい

minikube addons enable metrics-server

Istioを導入したい

minikube addons enable istio-provisioner
minikube addons enable istio

EFK Stackを導入したい

minikube addons enable efk

KibanaのDashboardが見たいときはminikube serviceコマンドを実行すると良いです。

$ minikube service -n kube-system kibana-logging
|-------------|----------------|-------------|---------------------------|
|  NAMESPACE  |      NAME      | TARGET PORT |            URL            |
|-------------|----------------|-------------|---------------------------|
| kube-system | kibana-logging |        5601 | http://192.168.49.2:30003 |
|-------------|----------------|-------------|---------------------------|
🎉  Opening service kube-system/kibana-logging in default browser...

kibanaもバッチリみられます。
スクリーンショット 2021-02-09 211603.png

(補足) minikube addons list

metrics-serverやefk、istio以外にもいろいろなaddonが提供されています。

$ minikube addons list
|-----------------------------|----------|--------------|
|         ADDON NAME          | PROFILE  |    STATUS    |
|-----------------------------|----------|--------------|
| ambassador                  | minikube | disabled     |
| csi-hostpath-driver         | minikube | disabled     |
| dashboard                   | minikube | disabled     |
| default-storageclass        | minikube | enabled ✅   |
| efk                         | minikube | disabled     |
| freshpod                    | minikube | disabled     |
| gcp-auth                    | minikube | disabled     |
| gvisor                      | minikube | disabled     |
| helm-tiller                 | minikube | disabled     |
| ingress                     | minikube | disabled     |
| ingress-dns                 | minikube | disabled     |
| istio                       | minikube | disabled     |
| istio-provisioner           | minikube | disabled     |
| kubevirt                    | minikube | disabled     |
| logviewer                   | minikube | disabled     |
| metallb                     | minikube | disabled     |
| metrics-server              | minikube | disabled     |
| nvidia-driver-installer     | minikube | disabled     |
| nvidia-gpu-device-plugin    | minikube | disabled     |
| olm                         | minikube | disabled     |
| pod-security-policy         | minikube | disabled     |
| registry                    | minikube | disabled     |
| registry-aliases            | minikube | disabled     |
| registry-creds              | minikube | disabled     |
| storage-provisioner         | minikube | enabled ✅   |
| storage-provisioner-gluster | minikube | disabled     |
| volumesnapshots             | minikube | disabled     |
|-----------------------------|----------|--------------|

おわりに

Docker Driverの対応に加えてMulti-Node Clusterも可能になったMinikube。
ぜひいろいろ遊んでみてください。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?