Kubernetes命令行工具 (kubectl)
作者:全棧行動派
kubectl 是 Kubernetes 集群的命令行工具,通過 kubectl 能夠對集群本身進行管理,并能 夠在集群上進行容器化應用的安裝部署。
1、概述
kubectl 是 Kubernetes 集群的命令行工具,通過 kubectl 能夠對集群本身進行管理,并能 夠在集群上進行容器化應用的安裝部署。
2、語法
使用以下語法從終端窗口運行 kubectl 命令:
kubectl [command] [TYPE] [NAME] [flags]
其中 command、TYPE、NAME 和 flags 分別是:
- command:指定要對一個或多個資源執(zhí)行的操作,例如 create、get、describe、delete。
- TYPE:指定資源類型。資源類型不區(qū)分大小寫, 可以指定單數、復數或縮寫形式。
- NAME:指定資源的名稱。名稱區(qū)分大小寫。 如果省略名稱,則顯示所有資源的詳細信息。例如:kubectl get pods。
- flags: 指定可選的參數。例如,可以使用 -s 或 --server 參數指定 Kubernetes API 服務器的地址和端口。
3、kubectl help 獲取更多信息
[root@k8s-master ~]# kubectl --help
kubectl controls the Kubernetes cluster manager.
Find more information at: https://kubernetes.io/docs/reference/kubectl/
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 在集群上運行特定鏡像
set 為對象設置指定特性
Basic Commands (Intermediate):
explain Get documentation for a resource
get 顯示一個或多個資源
edit 編輯服務器上的資源
delete Delete resources by file names, 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, replica set, or replication controller
autoscale Auto-scale a deployment, replica set, stateful set, or replication controller
Cluster Management Commands:
certificate 修改證書資源。
cluster-info Display cluster information
top Display resource (CPU/memory) usage
cordon 標記節(jié)點為不可調度
uncordon 標記節(jié)點為可調度
drain 清空節(jié)點以準備維護
taint 更新一個或者多個節(jié)點上的污點
Troubleshooting and Debugging Commands:
describe 顯示特定資源或資源組的詳細信息
logs 打印 Pod 中容器的日志
attach 掛接到一個運行中的容器
exec 在某個容器中執(zhí)行一個命令
port-forward 將一個或多個本地端口轉發(fā)到某個 Pod
proxy 運行一個指向 Kubernetes API 服務器的代理
cp Copy files and directories to and from containers
auth Inspect authorization
debug Create debugging sessions for troubleshooting workloads and nodes
Advanced Commands:
diff Diff the live version against a would-be applied version
apply Apply a configuration to a resource by file name or stdin
patch Update fields of a resource
replace Replace a resource by file name or stdin
wait Experimental: Wait for a specific condition on one or many resources
kustomize Build a kustomization target from a directory or URL.
Settings Commands:
label 更新某資源上的標簽
annotate 更新一個資源的注解
completion Output shell completion code for the specified shell (bash, zsh, fish, or powershell)
Other Commands:
alpha Commands for features in alpha
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 輸出客戶端和服務端的版本信息
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).
[root@k8s-master ~]#
4、kubectl子命令使用分類
(1)基礎命令
(2)部署和集群管理命令
(3)故障和調試命令
(4)其他命令
責任編輯:姜華
來源:
今日頭條