kubectl命令小妙招
阿新 • • 發佈:2020-10-29
kubectl命令使用大全
中文: http://docs.kubernetes.org.cn/683.html
當然,也可以寫入到/etc/profile裡.退出當前終端,重啟進去,以便載入source即可
[root@master-test ~]# kubectl --help 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 使用 replication controller, service, deployment 或者 pod 並暴露它作為一個 新的 Kubernetes Service run 在叢集中執行一個指定的映象 set 為 objects 設定一個指定的特徵 Basic Commands (Intermediate): explain 檢視資源的文件 get 顯示一個或更多 resources edit 在伺服器上編輯一個資源 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 自動調整一個 Deployment, ReplicaSet, 或者 ReplicationController 的副本數量 Cluster Management Commands: certificate 修改 certificate 資源. cluster-info 顯示叢集資訊 top Display Resource (CPU/Memory/Storage) usage. cordon 標記 node 為 unschedulable uncordon 標記 node 為 schedulable drain Drain node in preparation for maintenance taint 更新一個或者多個 node 上的 taints Troubleshooting and Debugging Commands: describe 顯示一個指定 resource 或者 group 的 resources 詳情 logs 輸出容器在 pod 中的日誌 attach Attach 到一個執行中的 container exec 在一個 container 中執行一個命令 port-forward Forward one or more local ports to a pod proxy 執行一個 proxy 到 Kubernetes API server cp 複製 files 和 directories 到 containers 和從容器中複製 files 和 directories. auth Inspect authorization Advanced Commands: diff Diff live version against would-be applied version apply 通過檔名或標準輸入流(stdin)對資源進行配置 patch 使用 strategic merge patch 更新一個資源的 field(s) replace 通過 filename 或者 stdin替換一個資源 wait Experimental: Wait for a specific condition on one or many resources. convert 在不同的 API versions 轉換配置檔案 kustomize Build a kustomization target from a directory or a remote url. Settings Commands: label 更新在這個資源上的 labels annotate 更新一個資源的註解 completion Output shell completion code for the specified shell (bash or zsh) Other Commands: api-resources Print the supported API resources on the server api-versions Print the supported API versions on the server, in the form of "group/version" config 修改 kubeconfig 檔案 plugin Provides utilities for interacting with plugins. version 輸出 client 和 server 的版本資訊 Usage: kubectl [flags] [options] Use "kubectl<command> --help" for more information about a given command. Use "kubectl options" for a list of global command-line options (applies to all commands).
那麼我希望能用kubectl Tab能補全命令需要怎麼做呢
在centos使用者下# cd ~;echo "source <(kubectl completion bash)" >> .bashrc或
# . <(kubectl completion bash)
一些實用命令
Q1:當kubectl get po 看到STATUS狀態不正常時怎麼查詢問題?
[root@master-test ~]# kubectl describe pods nginx-test-97c58fcc-9ncz2
還可以,檢視日誌
[root@master-test ~]# kubectl logs etcd-master-test -n kube-system