kubectl help可以查看kubectl相关的命令。

  1. Basic Commands (Beginner):
  2. create Create a resource from a file or from stdin.
  3. expose 使用 replication controller, service, deployment 或者 pod 并暴露它作为一个 新的
  4. Kubernetes Service
  5. run 在集群中运行一个指定的镜像
  6. set objects 设置一个指定的特征
  7. Basic Commands (Intermediate):
  8. explain 查看资源的文档
  9. get 显示一个或更多 resources
  10. edit 在服务器上编辑一个资源
  11. delete Delete resources by filenames, stdin, resources and names, or by resources and label selector
  12. Deploy Commands:
  13. rollout Manage the rollout of a resource
  14. scale Deployment, ReplicaSet, Replication Controller 或者 Job 设置一个新的副本数量
  15. autoscale 自动调整一个 Deployment, ReplicaSet, 或者 ReplicationController 的副本数量
  16. Cluster Management Commands:
  17. certificate 修改 certificate 资源.
  18. cluster-info 显示集群信息
  19. top Display Resource (CPU/Memory/Storage) usage.
  20. cordon 标记 node unschedulable
  21. uncordon 标记 node schedulable
  22. drain Drain node in preparation for maintenance
  23. taint 更新一个或者多个 node 上的 taints
  24. Troubleshooting and Debugging Commands:
  25. describe 显示一个指定 resource 或者 group resources 详情
  26. logs 输出容器在 pod 中的日志
  27. attach Attach 到一个运行中的 container
  28. exec 在一个 container 中执行一个命令
  29. port-forward Forward one or more local ports to a pod
  30. proxy 运行一个 proxy Kubernetes API server
  31. cp 复制 files directories containers 和从容器中复制 files directories.
  32. auth Inspect authorization
  33. Advanced Commands:
  34. apply 通过文件名或标准输入流(stdin)对资源进行配置
  35. patch 使用 strategic merge patch 更新一个资源的 field(s)
  36. replace 通过 filename 或者 stdin替换一个资源
  37. wait Experimental: Wait for one condition on one or many resources
  38. convert 在不同的 API versions 转换配置文件
  39. Settings Commands:
  40. label 更新在这个资源上的 labels
  41. annotate 更新一个资源的注解
  42. completion Output shell completion code for the specified shell (bash or zsh)
  43. Other Commands:
  44. alpha Commands for features in alpha
  45. api-resources Print the supported API resources on the server
  46. api-versions Print the supported API versions on the server, in the form of "group/version"
  47. config 修改 kubeconfig 文件
  48. plugin Runs a command-line plugin
  49. version 输出 client server 的版本信息

https://blog.csdn.net/miss1181248983/article/details/88037531

kubectl create

可以通过配置文件名或stdin创建一个集群资源对象。支持JSON和YAML格式的文件。

kubectl run

创建并运行一个或多个容器镜像。

kubectl set

用来配置应用资源,可以更改现有应用资源的一些信息。

kubectl explain

可以了解各个部分的说明和组成部分,类似于kubectl help。

kubectl get

获取列出一个或多个资源的信息。例如,分别获取当前集群中pod、deployment和svc的信息。

kubectl edit

用来编辑服务器上定义的资源。使用命令行工具获取的任何资源都可以使用edit命令编辑。

kubectl delete

可以通过配置文件名、stdin、资源名称或label选择器来删除资源。支持JSON和YAML格式的文件。

故障排查相关

kubectl describe

用来显示特定资源或资源组的详细信息。

kubectl logs

输出pod中一个容器的日志。如果pod只包含一个容器则可以省略容器名。

kubectl attach

连接到现有容器中一个正在运行的容器。

kubectl exec

在容器内部执行命令。类似于docker的exec命令。

kubectl port-forward

将一个或多个本地端口转发到pod。该命令不常用。

kubectl proxy

运行一个到Kubernetes API服务器的代理。建立一条通往API服务器的隧道,可以方便查看API服务器上的资源。该命令不常用。

kubectl cp

将文件和目录复制到容器或从容器复制到容器。

kubectl auth

用于身份验证检查授权。该命令不常用。


kubectl rollout

对资源进行管理。可用资源包括:deployment、daemonset。
子命令:

命令 说明
history 查看历史版本
pause 暂停资源
resume 恢复暂停资源
status 查看资源状态
undo 回滚版本

DaemonSet保证在每个Node上都运行一个容器副本,常用来部署一些集群的日志、监控或者其他系统管理应用。典型的应用包括:
日志收集,比如fluentd,logstash等
系统监控,比如Prometheus Node Exporter,collectd,New Relic agent,Ganglia gmond等
系统程序,比如kube-proxy, kube-dns, glusterd, ceph等
[

](https://blog.csdn.net/miss1181248983/article/details/88181434)

kubectl scale

用于横向扩展,扩容或缩容 Deployment、ReplicaSet、Replication Controller或Job 中Pod数量。

kubectl autoscale

自动设置在kubernetes集群中运行的pod数量(水平自动伸缩)。
指定Deployment、ReplicaSet或ReplicationController,并创建已经定义好资源的自动伸缩器。使用自动伸缩器可以根据需要自动增加或减少系统中部署的pod数量。


集群管理相关

kubectl certificate

用来修改证书资源。该命令不常用。

kubectl cluster-info

可以显示集群信息。

kubectl top

用于显示资源(CPU/内存/存储)使用情况。可用资源包括:node、pod。

kubectl cordon

将node标记为不可调度的状态,这样就不会让新创建的pod在此node上运行。

kubectl uncordon

将node标记为可调度的状态。

kubectl drain

可以让node在维护期间排除节点。drain本意排水,意思是将出问题的node下的pod转移到其它node下运行。

kubectl taint

用来更新一个或多个节点上的taint。该命令不常用。

节点亲和性是pod的一种属性(偏好或硬性要求),它使pod被吸引到一类特定的节点。taint 则相反,它使节点能够排斥一类特定的pod。

taint和toleration相互配合,可以用来避免pod被分配到不合适的节点上。每个节点上都可以应用一个或多个taint ,这表示对于那些不能容忍这些 taint 的 pod,是不会被该节点接受的。
如果将 toleration 应用于 pod 上,则表示这些 pod 可以(但不要求)被调度到具有匹配 taint 的节点上。
[

](https://blog.csdn.net/miss1181248983/article/details/88181434)



kubectl apply

通过文件名或标准输入(stdin)对资源进行配置。支持JSON和YAML格式的描述文件。

kubectl patch

用于更新资源的字段。当部分修改一些设定的时候patch非常有用。支持JSON和YAML格式。

kubectl replace

用文件名或标准输入替换资源。支持JSON和YAML格式。作用类似于apply,不同的是,apply不会删除原有resource,然后创建新的。apply直接在原有resource的基础上进行更新。同时kubectl apply还会resource中添加一条注释,标记当前的apply。类似于git操作。

kubectl label

用来更新(增加、修改或删除)资源上的 label(标签)。

kubectl annotate

用来更新一个或多个资源的注释信息。

kubectl completion

输出指定shell的代码完成命令 (bash or zsh)。该命令可用于自动补全。该命令不常用。

kubectl config
用来修改kubeconfig文件。