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

MyMemoWiki

「Kubectl」の版間の差分

提供: MyMemoWiki
ナビゲーションに移動 検索に移動
 
(同じ利用者による、間の11版が非表示)
1行目: 1行目:
 
| [[Kubernetes]] | [[MicroK8s]] | [[Minikube]] | [[Docker]] |
 
| [[Kubernetes]] | [[MicroK8s]] | [[Minikube]] | [[Docker]] |
 
==Kubectl==
 
==Kubectl==
 +
 +
{{amazon|4295004804}}
 +
 
[https://kubernetes.io/ja/docs/reference/kubectl/cheatsheet/ チートシート]
 
[https://kubernetes.io/ja/docs/reference/kubectl/cheatsheet/ チートシート]
 
*公式なクライアントは、kubectl
 
*公式なクライアントは、kubectl
17行目: 20行目:
 
*Kubectl が Kubernetes Master と通信するには、接続先サーバー情報や認証情報が必要となる
 
*Kubectl が Kubernetes Master と通信するには、接続先サーバー情報や認証情報が必要となる
 
*デフォルトでは、~/.kube/config に書かれている情報を使用して接続を行う
 
*デフォルトでは、~/.kube/config に書かれている情報を使用して接続を行う
 
+
*https://kubernetes.io/docs/reference/kubectl/overview/
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
32行目: 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
38行目: 45行目:
 
$ kubectl describe service -n kube-system kubernetes-dashboard
 
$ kubectl describe service -n kube-system kubernetes-dashboard
 
|-
 
|-
! scope="row"|kubectl  
+
! scope="row"|kubectl top
|  
+
| リソース使用量の確認
|
+
| $ kubectl top node
 +
|-
 +
! scope="row"|kubectl exec
 +
|  Podでコマンドを実行する(-itで対話実行)
 +
| $ kubectl exec -it nginx-pod -- /bin/sh
 +
|-
 +
! scope="row"|kubectl logs
 +
| Podのログ確認
 +
| $ kubectl logs nginx-pod
 
|-
 
|-
! scope="row"|kubectl  
+
! scope="row"|kubectl api-resources
 +
| サポートされているAPIリソースの一覧表示
 
|  
 
|  
|
 
 
|-
 
|-
! scope="row"|kubectl  
+
! scope="row"|kubectl explain
|  
+
| リソースのドキュメント
|
+
| $ kubectl explain nodes
 
|-
 
|-
 
! scope="row"|kubectl  
 
! scope="row"|kubectl  
71行目: 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 から利用する場合
  1. > 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
  1. kubectl controls the Kubernetes cluster manager.
  2.  
  3. Find more information at: https://kubernetes.io/docs/reference/kubectl/overview/
  4.  
  5. Basic Commands (Beginner):
  6. create Create a resource from a file or from stdin.
  7. expose Take a replication controller, service, deployment or pod and expose it as a new Kubernetes Service
  8. run Run a particular image on the cluster
  9. set Set specific features on objects
  10.  
  11. Basic Commands (Intermediate):
  12. explain Documentation of resources
  13. get Display one or many resources
  14. edit Edit a resource on the server
  15. delete Delete resources by filenames, stdin, resources and names, or by resources and label selector
  16.  
  17. Deploy Commands:
  18. rollout Manage the rollout of a resource
  19. scale Set a new size for a Deployment, ReplicaSet or Replication Controller
  20. autoscale Auto-scale a Deployment, ReplicaSet, or ReplicationController
  21.  
  22. Cluster Management Commands:
  23. certificate Modify certificate resources.
  24. cluster-info Display cluster info
  25. top Display Resource (CPU/Memory/Storage) usage.
  26. cordon Mark node as unschedulable
  27. uncordon Mark node as schedulable
  28. drain Drain node in preparation for maintenance
  29. taint Update the taints on one or more nodes
  30.  
  31. Troubleshooting and Debugging Commands:
  32. describe Show details of a specific resource or group of resources
  33. logs Print the logs for a container in a pod
  34. attach Attach to a running container
  35. exec Execute a command in a container
  36. port-forward Forward one or more local ports to a pod
  37. proxy Run a proxy to the Kubernetes API server
  38. cp Copy files and directories to and from containers.
  39. auth Inspect authorization
  40.  
  41. Advanced Commands:
  42. diff Diff live version against would-be applied version
  43. apply Apply a configuration to a resource by filename or stdin
  44. patch Update field(s) of a resource using strategic merge patch
  45. replace Replace a resource by filename or stdin
  46. wait Experimental: Wait for a specific condition on one or many resources.
  47. convert Convert config files between different API versions
  48. kustomize Build a kustomization target from a directory or a remote url.
  49.  
  50. Settings Commands:
  51. label Update the labels on a resource
  52. annotate Update the annotations on a resource
  53. completion Output shell completion code for the specified shell (bash or zsh)
  54.  
  55. Other Commands:
  56. alpha Commands for features in alpha
  57. api-versions Print the supported API versions on the server, in the form of "group/version"
  58. config Modify kubeconfig files
  59. plugin Provides utilities for interacting with plugins.
  60. version Print the client and server version information
  61.  
  62. Usage:
  63. kubectl [flags] [options]

kubectlインストール

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