k8s——kubernetes命令kubectl详解

1.kubectl管理命令

kubectl是管理k8s的命令行工具,通过生成json格式传递给apiserver进行一些操作

[root@master01 dashboard]# 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           在服务器上编辑一个资源    #直接编辑运行中的pod,serveice,控制器资源
  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          为 Deployment, ReplicaSet, Replication Controller 或者 Job 设置一个新的副本数量    #弹性伸缩中一个功能 设置副本数量
  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    #污点  一旦节点被标记为污点,则该节点不会被创建pod。调度器不会在上面创建

Troubleshooting and Debugging Commands:
  describe       显示一个指定 resource 或者 group 的 resources 详情   #Pod创建的过程及日志,都能查看,做排障
  logs           输出容器在 pod 中的日志   #作用于排障
  attach         Attach 到一个运行中的 container     #链接到容器,不是进入,远程连接
  exec           在一个 container 中执行一个命令   #进入到容器
  port-forward   Forward one or more local ports to a pod  #端口转发 转发到一个或多个本地端口
  proxy          运行一个 proxy 到 Kubernetes API server    #代理apiserver
  cp             复制 files 和 directories 到 containers 和从容器中复制 files 和 directories.  #复制
  auth           Inspect authorization   #验证

Advanced Commands:
  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 转换配置文件  #做k8s二次开发

Settings Commands:
  label          更新在这个资源上的 labels    #打标签
  annotate       更新一个资源的注解  #注释
  completion     Output shell completion code for the specified shell (bash or zsh)  #输出 为指定的shell (bash或zsh)输出shell完成代码

Other Commands:
  alpha          Commands for features in alpha   #alpha命令用于alpha中的特性
  api-resources  Print the supported API resources on the server   #查看缩写,打印服务器上支持的API资源
  api-versions   Print the supported API versions on the server, in the form of "group/version"  #在服务器上以“组/版本”的形式打印支持的API版本
  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.#使用“kubectl <command>—help”获得关于给定命令的更多信息。
Use "kubectl options" for a list of global command-line options (applies to all commands).#使用“kubectl options”作为全局命令行选项列表(适用于所有命令)。

可以查看资源对象的缩写

[root@master dashboard]# kubectl api-resources

2.pod,service,deployment,replicaset四者关系

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
先创建再删除,维持副本的数量
在这里插入图片描述
在这里插入图片描述
控制器会记载着历史的版本
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值