官网 kebectl 命令参考:https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands
帮助命令: kubectl --help

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

显示客户端及服务端程序版本信息:

  1. $ kubectl version --short true
  2. Client Version: v1.18.0
  3. Server Version: v1.18.0

获取集群信息

  1. $ kubectl cluster-info
  2. Kubernetes master is running at https://192.168.22.1:6443
  3. KubeDNS is running at https://192.168.22.1:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

创建资源对象

  1. $ kubectl run NAME --image=image [--env="key=value"] [--port=port] [--replicas=replicas] [--dry-run=bool] [--overrides=inline-json] [--command] -- [COMMAND] [args...]

例:启动Nginx