LoginSignup
3
2

More than 1 year has passed since last update.

個人的kubectlチートシート

Last updated at Posted at 2020-11-07

公式のチートシートが以下にあるので,これで十分だと思います.

kubectlチートシート | Kubernetes

個人的によく使うものをチートシートを作りました.

リソースの操作

作成/更新

kubectl apply -f xxx.yaml

削除

kubectl delete -f xxx.yaml

ネームスペースの操作

新規作成

kubectl create namespace <namespace>

確認(一覧)

kubectl get ns

デフォルトネームスペースを変更

kubectl config set-context --current --namespace=dev-koyama

現在のネームスペースを取得

kubectl config view -o jsonpath='{.contexts[].context.namespace}' ; echo

コンテキストの操作

現在のコンテキスト

kubectl config current-context

利用できるコンテキスト一覧

kubectl config get-contexts

使用するコンテキストを設定

kubectl config use-context <CONTEXT_NAME>

ラベルの操作

Podごとのラベル一覧

kubectl get pods --show-labels

サービスの操作

ServiceのTypeをNodePortへ変更

kubectl patch service my-svc -p '{"spec":{"type":"NodePort"}}'

クラスタの操作

現在の設定を確認

kubectl config get-contexts

設定を変更

kubectl config use-context docker-desktop

コンテナでコマンドを実行

podが複数コンテナの場合

kubectl exec <pod_name> --container <container_name> -- <command> 

podが単一コンテナの場合

kubectl exec <pod_name> -- <command> 

コンテナのシェルに入る

podが複数コンテナの場合

kubectl exec -it <pod_name> --container <container_name> -- /bin/bash

podが単一コンテナの場合

kubectl exec -it <pod_name> -- /bin/bash

レプリカ数の変更

kubectl scale --replicas=1 -f rs.yaml

デバッグ用コンテナを1つデプロイ

--rm をつけるとexitするとコンテナが消える.

kubectl run -it --rm ubuntu --image=ubuntu:18.04 /bin/bash
3
2
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
3
2