Kubernetesでよく使うコマンド紹介




便利ツールkube-promptをインストール

kube-promptはkubectlコマンドの補完を行ってくれるツールでKubernetesを扱うなら使うべきツールだと思います。ちなみに日本人のSHIBATAさんが作っています。

Macの場合インストールは簡単です。

$ brew tap c-bata/kube-prompt
$ brew install kube-prompt

インストール後に下記を実行するだけで使えるようになります。

$ kube-prompt
kube-prompt v1.0.3 (rev-ba1a338)
Please use exit or Ctrl-D to exit this program..

run

runコマンドでimageからpodを作成することができます。

>>> run nginx --image=nginx:latest --port=80
deployment "nginx" created

get pod

getコマンドでpod、service、ingress、deploymentのステータスを確認することができます。

>>> get pod
NAME                     READY     STATUS              RESTARTS   AGE
nginx-6bfb654d7c-t24l6   1/1       Running             0          2m

deploymentの場合

>>> get deployments
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx     1         1         1            1           10m

describe

podなどの詳細な情報を確認することができます。

>>> describe pod nginx-6bfb654d7c-t24l6
Name:           nginx-6bfb654d7c-t24l6
Namespace:      default
Node:           minikube/10.0.2.15
Start Time:     Sun, 08 Jul 2018 14:57:30 +0900
Labels:         pod-template-hash=2696210837
                run=nginx
Annotations:    <none>
Status:         Running
IP:             172.17.0.5
Controlled By:  ReplicaSet/nginx-6bfb654d7c
Containers:
  nginx:
    Container ID:   docker://ab97d82600e8879fe6b81f9823ced3176eee1215226a8fa4ccdabff73ae7f4e2
    Image:          nginx:latest
    Image ID:       docker-pullable://nginx@sha256:a65beb8c90a08b22a9ff6a219c2f363e16c477b6d610da28fe9cba37c2c3a2ac
    Port:           80/TCP
    State:          Running
      Started:      Sun, 08 Jul 2018 14:57:52 +0900
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-sx9s9 (ro)

exec

dockerのときと同じ操作ですね。

>>> exec -it nginx-6bfb654d7c-t24l6 bash
root@nginx-6bfb654d7c-t24l6:/#

config get-contexts

使用できるKubernetesのクラスタ一覧を確認できます。

>>> config get-contexts
CURRENT   NAME       CLUSTER    AUTHINFO   NAMESPACE
*         minikube   minikube   minikube

config current-config

現在選択中のクラスタを表示します。

>>> config current-context
minikube

config use-config

使用するクラスタを変更できます。

>>> config use-context minikube
Switched to context "minikube".
The following two tabs change content below.

髙妻智一

2013年CyberAgent新卒入社 スマホゲームを作る子会社に所属し、サーバーサイドのエンジニアを担当。2年目の終わりから新規子会社の立ち上げに参加し、サーバーサイドのエンジニアリーダーとしてサービースのリリースから運用までを担当。 2018年仮想通貨のスマホウォレットを提供するGinco Incにブロックチェーンエンジニアとして入社。






よく読まれている関連記事はこちら




コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です