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

MyMemoWiki

「Kubectl」の版間の差分

提供: MyMemoWiki
ナビゲーションに移動 検索に移動
 
(同じ利用者による、間の6版が非表示)
20行目: 20行目:
 
*Kubectl が Kubernetes Master と通信するには、接続先サーバー情報や認証情報が必要となる
 
*Kubectl が Kubernetes Master と通信するには、接続先サーバー情報や認証情報が必要となる
 
*デフォルトでは、~/.kube/config に書かれている情報を使用して接続を行う
 
*デフォルトでは、~/.kube/config に書かれている情報を使用して接続を行う
 
+
*https://kubernetes.io/docs/reference/kubectl/overview/
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
35行目: 35行目:
 
| $ kubectl get nodes
 
| $ kubectl get nodes
 
$ kubectl get service -n kube-system
 
$ kubectl get service -n kube-system
 +
|-
 +
! scope="row"|kubectl run
 +
| イメージをPodで作成、実行
 +
| $ kubectl run nginx --image=nginx
 
|-
 
|-
 
! scope="row"|kubectl describe
 
! scope="row"|kubectl describe
46行目: 50行目:
 
|-
 
|-
 
! scope="row"|kubectl exec
 
! scope="row"|kubectl exec
|  Podでコマンドを実行する
+
|  Podでコマンドを実行する(-itで対話実行)
 
| $ kubectl exec -it nginx-pod -- /bin/sh
 
| $ kubectl exec -it nginx-pod -- /bin/sh
 
|-
 
|-
52行目: 56行目:
 
| Podのログ確認
 
| Podのログ確認
 
| $ kubectl logs nginx-pod
 
| $ kubectl logs nginx-pod
 +
|-
 +
! scope="row"|kubectl api-resources
 +
| サポートされているAPIリソースの一覧表示
 +
|
 +
|-
 +
! scope="row"|kubectl explain
 +
| リソースのドキュメント
 +
| $ kubectl explain nodes
 
|-
 
|-
 
! scope="row"|kubectl  
 
! scope="row"|kubectl  
74行目: 86行目:
 
|-
 
|-
 
|}
 
|}
 +
 +
<pre>
 +
kubectl controls the Kubernetes cluster manager.
 +
 +
Find more information at: https://kubernetes.io/docs/reference/kubectl/overview/
 +
 +
Basic Commands (Beginner):
 +
  create        Create a resource from a file or from stdin.
 +
  expose        Take a replication controller, service, deployment or pod and expose it as a new Kubernetes Service
 +
  run          Run a particular image on the cluster
 +
  set          Set specific features on objects
 +
 +
Basic Commands (Intermediate):
 +
  explain      Documentation of resources
 +
  get          Display one or many resources
 +
  edit          Edit a resource on the server
 +
  delete        Delete resources by filenames, stdin, resources and names, or by resources and label selector
 +
 +
Deploy Commands:
 +
  rollout      Manage the rollout of a resource
 +
  scale        Set a new size for a Deployment, ReplicaSet or Replication Controller
 +
  autoscale    Auto-scale a Deployment, ReplicaSet, or ReplicationController
 +
 +
Cluster Management Commands:
 +
  certificate  Modify certificate resources.
 +
  cluster-info  Display cluster info
 +
  top          Display Resource (CPU/Memory/Storage) usage.
 +
  cordon        Mark node as unschedulable
 +
  uncordon      Mark node as schedulable
 +
  drain        Drain node in preparation for maintenance
 +
  taint        Update the taints on one or more nodes
 +
 +
Troubleshooting and Debugging Commands:
 +
  describe      Show details of a specific resource or group of resources
 +
  logs          Print the logs for a container in a pod
 +
  attach        Attach to a running container
 +
  exec          Execute a command in a container
 +
  port-forward  Forward one or more local ports to a pod
 +
  proxy        Run a proxy to the Kubernetes API server
 +
  cp            Copy files and directories to and from containers.
 +
  auth          Inspect authorization
 +
 +
Advanced Commands:
 +
  diff          Diff live version against would-be applied version
 +
  apply        Apply a configuration to a resource by filename or stdin
 +
  patch        Update field(s) of a resource using strategic merge patch
 +
  replace      Replace a resource by filename or stdin
 +
  wait          Experimental: Wait for a specific condition on one or many resources.
 +
  convert      Convert config files between different API versions
 +
  kustomize    Build a kustomization target from a directory or a remote url.
 +
 +
Settings Commands:
 +
  label        Update the labels on a resource
 +
  annotate      Update the annotations on a resource
 +
  completion    Output shell completion code for the specified shell (bash or zsh)
 +
 +
Other Commands:
 +
  alpha        Commands for features in alpha
 +
  api-versions  Print the supported API versions on the server, in the form of "group/version"
 +
  config        Modify kubeconfig files
 +
  plugin        Provides utilities for interacting with plugins.
 +
  version      Print the client and server version information
 +
 +
Usage:
 +
  kubectl [flags] [options]
 +
</pre>
  
 
===kubectlインストール===
 
===kubectlインストール===

2021年2月10日 (水) 14:19時点における最新版

| Kubernetes | MicroK8s | Minikube | Docker |

Kubectl

チートシート

  • 公式なクライアントは、kubectl
  • kubectlを使用してクラスターと対話できるようになります
  • Kubernetes APIと連携するコマンドラインツール
  • minikube から利用する場合
> minikube kubectl version

チートシート

kubectlコマンド

  • Kubernetesでは、クラスタの操作は全て、Kubernetes Masterの APIを介して行われる
  • 手動で操作する場合には、CLIツールの kubectl を利用するのが一般的
  • Kubectl が Kubernetes Master と通信するには、接続先サーバー情報や認証情報が必要となる
  • デフォルトでは、~/.kube/config に書かれている情報を使用して接続を行う
  • https://kubernetes.io/docs/reference/kubectl/overview/
コマンド 内容
kubectl version クライアントkubectlおよびAPIサーバーのバージョンを表示
kubectl get リソースの情報を表示 $ kubectl get nodes

$ kubectl get service -n kube-system

kubectl run イメージをPodで作成、実行 $ kubectl run nginx --image=nginx
kubectl describe リソースの詳細情報 $ kubectl describe nodes

$ kubectl describe service -n kube-system kubernetes-dashboard

kubectl top リソース使用量の確認 $ kubectl top node
kubectl exec Podでコマンドを実行する(-itで対話実行) $ kubectl exec -it nginx-pod -- /bin/sh
kubectl logs Podのログ確認 $ kubectl logs nginx-pod
kubectl api-resources サポートされているAPIリソースの一覧表示
kubectl explain リソースのドキュメント $ kubectl explain nodes
kubectl
kubectl
kubectl
kubectl
kubectl
kubectl controls the Kubernetes cluster manager.

 Find more information at: https://kubernetes.io/docs/reference/kubectl/overview/

Basic Commands (Beginner):
  create        Create a resource from a file or from stdin.
  expose        Take a replication controller, service, deployment or pod and expose it as a new Kubernetes Service
  run           Run a particular image on the cluster
  set           Set specific features on objects

Basic Commands (Intermediate):
  explain       Documentation of resources
  get           Display one or many resources
  edit          Edit a resource on the server
  delete        Delete resources by filenames, stdin, resources and names, or by resources and label selector

Deploy Commands:
  rollout       Manage the rollout of a resource
  scale         Set a new size for a Deployment, ReplicaSet or Replication Controller
  autoscale     Auto-scale a Deployment, ReplicaSet, or ReplicationController

Cluster Management Commands:
  certificate   Modify certificate resources.
  cluster-info  Display cluster info
  top           Display Resource (CPU/Memory/Storage) usage.
  cordon        Mark node as unschedulable
  uncordon      Mark node as schedulable
  drain         Drain node in preparation for maintenance
  taint         Update the taints on one or more nodes

Troubleshooting and Debugging Commands:
  describe      Show details of a specific resource or group of resources
  logs          Print the logs for a container in a pod
  attach        Attach to a running container
  exec          Execute a command in a container
  port-forward  Forward one or more local ports to a pod
  proxy         Run a proxy to the Kubernetes API server
  cp            Copy files and directories to and from containers.
  auth          Inspect authorization

Advanced Commands:
  diff          Diff live version against would-be applied version
  apply         Apply a configuration to a resource by filename or stdin
  patch         Update field(s) of a resource using strategic merge patch
  replace       Replace a resource by filename or stdin
  wait          Experimental: Wait for a specific condition on one or many resources.
  convert       Convert config files between different API versions
  kustomize     Build a kustomization target from a directory or a remote url.

Settings Commands:
  label         Update the labels on a resource
  annotate      Update the annotations on a resource
  completion    Output shell completion code for the specified shell (bash or zsh)

Other Commands:
  alpha         Commands for features in alpha
  api-versions  Print the supported API versions on the server, in the form of "group/version"
  config        Modify kubeconfig files
  plugin        Provides utilities for interacting with plugins.
  version       Print the client and server version information

Usage:
  kubectl [flags] [options]

kubectlインストール

$ curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
$ sudo chmod +x ./kubectl
$ sudo install kubectl /usr/local/bin