玩k8s----kubectl命令行管理工具

本文介绍了kubectl,Kubernetes集群的主要管理工具,包括基本指令、应用生命周期管理和pod资源调度。kubectl用于创建、发布、更新、回滚和删除应用,通过clusterIP:port或nodeIP:nodePort访问service,并详细解释了port、nodePort、targetPort和containerPort的区别。此外,文章还讨论了pod的调度机制,如kube-proxy的负载均衡和不同模式。使用kubectl能实现快速部署、自我修复和提高资源利用率等优势。
摘要由CSDN通过智能技术生成

玩k8s----kubectl命令行管理工具

一:Kubectl管理

1.1: Kubectl 基本指令

  • kubectl是管理k8s的命令行工具,通过生成json格式传递给apiserver进行一些操作
  • 更全的kubectl命令请查看kubectl --help,以下仅列出常用的命令
  • 查看更详细的帮助信息 kubectl create --help查看create命令帮助信息
[root@localhost bin]# 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           在服务器上编辑一个资源
  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    '污点'

Troubleshooting and Debugging Commands:
  describe       显示一个指定 resource 或者 group  resources 详情  '多用于排障时'
  logs           输出容器在 pod 中的日志    '多用于排障时'
  attach         Attach 到一个运行中的 container		'用于连接到一个容器,相当于远程连接'
  exec           在一个 container 中执行一个命令   '进入容器'
  port-forward   Forward one or more local ports to a pod   '端口转发'
  proxy          运行一个 proxy  Kubernetes API server    '代理'
  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 转换配置文件

Settings Commands:
  label          更新在这个资源上的 labels    '打标签'
  annotate       更新一个资源的注解
  completion     Output shell completion code for the specified shell (bash or
zsh)   '输出shell终端的代码到指定的shell'

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        输出 client  server 的版本信息

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).

命令 描述
create 通过文件名或标准输入创建资源
expose 将一个资源公开为一个新的Service
run 在集群中运行一个特定的镜像
set 在对象上设置特定的功能
get 显示一个或多个资源
explain 文档参考资料
edit 使用默认的编辑器编辑一个资源。
delete 通过文件名、标准输入、资源名称或标签选择器来删除资源。
rollout 管理资源的发布
rolling-update 对给定的复制控制器滚动更新
scale 扩容或缩容Pod数量,Deployment、ReplicaSet、RC或Job
autoscale 创建一个自动选择扩容或缩容并设置Pod数量
certificate 修改证书资源
cluster-info 显示集群信息
top 显示
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值