概要
本投稿はminikube
を使用し、K8sの基本動作を抑えることを目的とした個人メモです。
前提条件
- MacOSに
minikube
,kubectl
がインストール済みであること。 - K8sクラスタが起動していること
$ minikube start
クラスタ構成の確認
以下コマンドではK8sマスタIPアドレス
と、内部DNSエンドポイントが表示される。
kubectlコマンドがマスターと通信できない場合はエラーとなるため、minikube stop
実行後、再度クラスタを立ち上げること
$ kubectl cluster-info
Kubernetes master is running at https://192.168.99.100:8443
KubeDNS is running at https://192.168.99.100:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
kubernetes-dashboard is running at https://192.168.99.100:8443/api/v1/namespaces/kube-system/services/kubernetes-dashboard/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'
nodeの確認方法は以下の通り。
マルチノード構成の場合はマスタの他にワーカーノードも表示される。
$ kubectl get node
NAME STATUS ROLES AGE VERSION
minikube Ready <none> 9m v1.4.5
ポッドの実行
今回はhello-world
イメージを使用し、ポッドの立ち上げを行う。
$ kubectl run hello-world --image=hello-world -it --restart=Never
また、既に同じポッドが立ち上がっている場合は以下のようなエラーとなる。
$ kubectl run hello-world --image=hello-world -it --restart=Never
Error from server (AlreadyExists): pods "hello-world" already exists
ポッドの状態は以下コマンドで確認することが可能。
$ kubectl get pod
NAME READY STATUS RESTARTS AGE
hello-world 0/1 Completed 0 3m
ポッドを削除する場合はdelete
を行う。
$ kubectl delete pod hello-world
pod "hello-world" deleted
削除後はポッドが起動していないことを確認できる。
$ kubectl get pod
No resources found.
ログを確認する場合は以下の通り。
$ kubectl logs hello-world