官网 kebectl 命令参考:https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands
帮助命令: kubectl --help
# 基本命令(入门)Basic Commands (Beginner):create Create a resource from a file or from stdin.expose 使用 replication controller, service, deployment 或者 pod 并暴露它作为一个 新的 KubernetesServicerun 在集群中运行一个指定的镜像set 为 objects 设置一个指定的特征# 基本命令(中级)Basic Commands (Intermediate):explain 查看资源的文档get 显示一个或更多 resourcesedit 在服务器上编辑一个资源delete Delete resources by filenames, stdin, resources and names, or by resources and label selector# 部署命令Deploy Commands:rollout Manage the rollout of a resourcescale Set a new size for a Deployment, ReplicaSet or Replication Controllerautoscale 自动调整一个 Deployment, ReplicaSet, 或者 ReplicationController 的副本数量# 集群管理命令Cluster Management Commands:certificate 修改 certificate 资源.cluster-info 显示集群信息top Display Resource (CPU/Memory/Storage) usage.cordon 标记 node 为 unschedulableuncordon 标记 node 为 schedulabledrain Drain node in preparation for maintenancetaint 更新一个或者多个 node 上的 taints# 故障排除和调试命令Troubleshooting and Debugging Commands:describe 显示一个指定 resource 或者 group 的 resources 详情logs 输出容器在 pod 中的日志attach Attach 到一个运行中的 containerexec 在一个 container 中执行一个命令port-forward Forward one or more local ports to a podproxy 运行一个 proxy 到 Kubernetes API servercp 复制 files 和 directories 到 containers 和从容器中复制 files 和 directories.auth Inspect authorization# 高级命令Advanced Commands:diff Diff live version against would-be applied versionapply 通过文件名或标准输入流(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 更新在这个资源上的 labelsannotate 更新一个资源的注解completion Output shell completion code for the specified shell (bash or zsh)# 其他命令Other Commands:alpha Commands for features in alphaapi-resources Print the supported API resources on the serverapi-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 的版本信息
显示客户端及服务端程序版本信息:
$ kubectl version --short trueClient Version: v1.18.0Server Version: v1.18.0
获取集群信息
$ kubectl cluster-infoKubernetes master is running at https://192.168.22.1:6443KubeDNS is running at https://192.168.22.1:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
创建资源对象
$ kubectl run NAME --image=image [--env="key=value"] [--port=port] [--replicas=replicas] [--dry-run=bool] [--overrides=inline-json] [--command] -- [COMMAND] [args...]
例:启动Nginx
