| ページ一覧 | ブログ | twitter |  書式 | 書式(表) |

MyMemoWiki

Minikube

提供: MyMemoWiki
2020年11月17日 (火) 08:43時点におけるPiroto (トーク | 投稿記録)による版 (ページの作成:「| Kubernetes | MicroK8s | Docker | ==minikube== *https://github.com/kubernetes/minikube *ローカル開発や学習、テスト用のシンプルなKuberne…」)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
ナビゲーションに移動 検索に移動

| Kubernetes | MicroK8s | Docker |

minikube

インストール

Ubuntu + 仮想環境

入手

  1. $ curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
  2. $ sudo +x minkube

インストール

  1. $ sudo install minikube /usr/local/bin

利用

ローカルクラスタの作成

  • ローカル仮想マシンを作成
  • Kubernetesを設定
  • kubectlを設定
  1. > minikube start
  • VirtualBox

0753 minikube.png

  • Ubuntu+KVM

Minikube kvm.png

クラスタの確認

  1. $ kubectl config get-contexts

  2. CURRENT NAME CLUSTER AUTHINFO NAMESPACE

  3. * minikube minikube minikube

停止

  1. > minikube stop

クラスタを削除

  1. > minikube delete

ダッシュボード

  1. $ minikube dashboard

Minikube dashboard.png

コマンド

コマンド 内容
ssh minikube の環境にログインします(デバッグ用)

Kubernetes Deploymentを作る

  • 単純なHTTPサーバーであるechoserverという既存のイメージを使用して、Kubernetes Deploymentを作る
  • --portを使用して8080番ポートで公開
  1. $ kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.10
  2. deployment.apps/hello-minikube created

K8s deploy.png

Deploymentに接続するために、Serviceとして公開

  1. $ kubectl expose deployment hello-minikube --type=NodePort --port=8080
  2. service/hello-minikube exposed

K8s service.png

Podが起動しているか確認

  1. $ kubectl get pod
  2. NAME READY STATUS RESTARTS AGE
  3. hello-minikube-64b64df8c9-jzm5v 1/1 Running 0 11m

公開サービスのURLを確認

  1. $ minikube service hello-minikube --url
  2. http://192.168.39.214:31429

K8s service run.png

クラスタのステータス

  • Serverとクライアントのバージョン
  1. $ kubectl version
  2. Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.8", GitCommit:"9f2892aab98fe339f3bd70e3c470144299398ace", GitTreeState:"clean", BuildDate:"2020-08-13T16:12:48Z", GoVersion:"go1.13.15", Compiler:"gc", Platform:"linux/amd64"}
  3. Server Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.3", GitCommit:"2e7996e3e2712684bc73f0dec0200d64eec7fe40", GitTreeState:"clean", BuildDate:"2020-05-20T12:43:34Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}
  • クラスタを構成しているコンポーネントを確認
  1. $ kubectl get componentstatus
  2. NAME STATUS MESSAGE ERROR
  3. controller-manager Healthy ok
  4. scheduler Healthy ok
  5. etcd-0 Healthy {"health":"true"}

ワーカーノードの表示

  • クラスタ上の全のノードを表示
  1. $ kubectl get nodes
  2. NAME STATUS ROLES AGE VERSION
  3. minikube Ready master 3h13m v1.18.3

ノードの詳細情報

  • kubectl describe nodes [ノード名]
基本情報が最初に表示される
  1. Name: minikube
  2. Roles: master
  3. Labels: beta.kubernetes.io/arch=amd64
  4. beta.kubernetes.io/os=linux
  5. kubernetes.io/arch=amd64
  6. kubernetes.io/hostname=minikube
  7. kubernetes.io/os=linux
  8. node-role.kubernetes.io/master=
  9. Annotations: kubeadm.alpha.kubernetes.io/cri-socket: /var/run/dockershim.sock
  10. node.alpha.kubernetes.io/ttl: 0
  11. volumes.kubernetes.io/controller-managed-attach-detach: true
  12. CreationTimestamp: Mon, 05 Aug 2019 23:17:24 +0900
  13. Taints: <none>
  14. Unschedulable: false
ノード上で動いているオペレーションの情報が表示される
  • それぞれのノードが十分なディスクとメモリを持っているか
  • Kubernatesマスターに対して正常であるか
  1. Conditions:
  2. Type Status LastHeartbeatTime LastTransitionTime Reason Message
  3. ---- ------ ----------------- ------------------ ------ -------
  4. MemoryPressure False Tue, 13 Aug 2019 01:01:05 +0900 Mon, 05 Aug 2019 23:17:15 +0900 KubeletHasSufficientMemory kubelet has sufficient memory available
  5. DiskPressure False Tue, 13 Aug 2019 01:01:05 +0900 Mon, 05 Aug 2019 23:17:15 +0900 KubeletHasNoDiskPressure kubelet has no disk pressure
  6. PIDPressure False Tue, 13 Aug 2019 01:01:05 +0900 Mon, 05 Aug 2019 23:17:15 +0900 KubeletHasSufficientPID kubelet has sufficient PID available
  7. Ready True Tue, 13 Aug 2019 01:01:05 +0900 Mon, 05 Aug 2019 23:17:15 +0900 KubeletReady kubelet is posting ready status
  8. Addresses:
  9. InternalIP: 10.0.2.15
  10. Hostname: minikube
マシンのキャパシティ情報の表示
  1. Capacity:
  2. cpu: 2
  3. ephemeral-storage: 17784772Ki
  4. hugepages-2Mi: 0
  5. memory: 2038624Ki
  6. pods: 110
  7. Allocatable:
  8. cpu: 2
  9. ephemeral-storage: 16390445849
  10. hugepages-2Mi: 0
  11. memory: 1936224Ki
  12. pods: 110
ノード上のソフトウェアバージョンの表示
  1. System Info:
  2. Machine ID: 7ec5a55cfdc14693866eccf4e9a1228f
  3. System UUID: 2C88347D-32CC-4F26-9AEE-1FED259A233C
  4. Boot ID: 1da81daa-4519-4f04-afe0-64efecedd7e7
  5. Kernel Version: 4.15.0
  6. OS Image: Buildroot 2018.05.3
  7. Operating System: linux
  8. Architecture: amd64
  9. Container Runtime Version: docker://18.9.6
  10. Kubelet Version: v1.15.0
  11. Kube-Proxy Version: v1.15.0
ノード上で動いているPod情報の表示
  1. Non-terminated Pods: (9 in total)
  2. Namespace Name CPU Requests CPU Limits Memory Requests Memory Limits AGE
  3. --------- ---- ------------ ---------- --------------- ------------- ---
  4. kube-system coredns-5c98db65d4-j24hp 100m (5%) 0 (0%) 70Mi (3%) 170Mi (8%) 7d1h
  5. kube-system coredns-5c98db65d4-phtm8 100m (5%) 0 (0%) 70Mi (3%) 170Mi (8%) 7d1h
  6. kube-system etcd-minikube 0 (0%) 0 (0%) 0 (0%) 0 (0%) 7d1h
  7. kube-system kube-addon-manager-minikube 5m (0%) 0 (0%) 50Mi (2%) 0 (0%) 7d1h
  8. kube-system kube-apiserver-minikube 250m (12%) 0 (0%) 0 (0%) 0 (0%) 7d1h
  9. kube-system kube-controller-manager-minikube 200m (10%) 0 (0%) 0 (0%) 0 (0%) 7d1h
  10. kube-system kube-proxy-wrgp5 0 (0%) 0 (0%) 0 (0%) 0 (0%) 7d1h
  11. kube-system kube-scheduler-minikube 100m (5%) 0 (0%) 0 (0%) 0 (0%) 7d1h
  12. kube-system storage-provisioner 0 (0%) 0 (0%) 0 (0%) 0 (0%) 7d1h
  13. Allocated resources:
  14. (Total limits may be over 100 percent, i.e., overcommitted.)
  15. Resource Requests Limits
  16. -------- -------- ------
  17. cpu 755m (37%) 0 (0%)
  18. memory 190Mi (10%) 340Mi (17%)
  19. ephemeral-storage 0 (0%) 0 (0%)
  20. Events:
  21. Type Reason Age From Message
  22. ---- ------ ---- ---- -------
  23. Normal NodeHasSufficientMemory 7d1h (x8 over 7d1h) kubelet, minikube Node minikube status is now: NodeHasSufficientMemory
  24. Normal NodeHasNoDiskPressure 7d1h (x8 over 7d1h) kubelet, minikube Node minikube status is now: NodeHasNoDiskPressure
  25. Normal NodeHasSufficientPID 7d1h (x7 over 7d1h) kubelet, minikube Node minikube status is now: NodeHasSufficientPID
  26. Normal Starting 7d1h kube-proxy, minikube Starting kube-proxy.
  27. Normal Starting 12m kubelet, minikube Starting kubelet.
  28. Normal NodeHasSufficientMemory 12m (x8 over 12m) kubelet, minikube Node minikube status is now: NodeHasSufficientMemory
  29. Normal NodeHasNoDiskPressure 12m (x8 over 12m) kubelet, minikube Node minikube status is now: NodeHasNoDiskPressure
  30. Normal NodeHasSufficientPID 12m (x7 over 12m) kubelet, minikube Node minikube status is now: NodeHasSufficientPID
  31. Normal NodeAllocatableEnforced 12m kubelet, minikube Updated Node Allocatable limit across pods
  32. Normal Starting 11m kube-proxy, minikube Starting kube-proxy

クラスタのコンポーネント

  • Kubernetesクラスタを構成する多くのコンポーネントが、Kubernetes自体を使ってデプロイされる
  • kube-system Namesspace内で動作

Kubernetes proxy

  • クラスタ内のロードバランスされたServiceにネットワークトラフィックをルーティング
  • クラスタ内の各ノードで動いている必要がある
  • DaemonSetというAPIオブジェクトが多くのクラスタではノードでプロキシを動作させるために利用される

Namespace

  • クラスタ内のオブジェクトを構造化
  • kubectlはデフォルトではdefaultというNamespaceとやり取り
  • --namespace で指定できる

Context

  • デフォルトのNamespaceを恒久的に変更したい場合
  • $HOME/.kube/config に保存される

Kubernetes APIオブジェクトの参照