User-Profile-Image
hankin
  • 5
  • centos7
  • docker
  • mysql
  • PostgreSQL
  • git/gitlab
  • ELK
  • python
    • python-Tornado
    • python-django
  • redis
  • nginx
  • kvm
  • proxmox
  • mongo
  • kubernetes
  • prometheus
  • GlusterFs
  • nfs
  • freeswitch
  • httpd
  • shell脚本
  • linux
  • fastdfs
  • nextcloud
  • openssl
  • openvpn
  • rabbitmq
  • sqlite
  • svn
  • java
  • ubuntu
  • vue2
  • wordpress
  • php
  • IOT物联网
  • 项目
  • 故障处理
  • 树莓派
  • 博客存档
  • 未分类
  • 杂项
  • #1742(无标题)
  • 新视野
  • 分类
    • 项目
    • 树莓派
    • 杂项
    • 未分类
    • 新视野
    • 故障处理
    • 博客存档
    • 交换机
    • wordpress
    • vue2
    • ubuntu
    • svn
    • sqlite
    • shell脚本
    • redis
    • rabbitmq
    • python-django
    • python
    • proxmox
    • prometheus
    • PostgreSQL
    • php
    • openvpn
    • openssl
    • nginx
    • nfs
    • nextcloud
    • mysql
    • mongo
    • linux
    • kvm
    • kubernetes
    • java
    • IOT物联网
    • httpd
    • GlusterFs
    • git/gitlab
    • freeswitch
    • fastdfs
    • ELK
    • docker
    • centos7
  • 页面
    • #1742(无标题)
  • 友链
      请到[后台->主题设置->友情链接]中设置。
Help?

Please contact us on our email for need any support

Support
    首页   ›   kubernetes   ›   正文
kubernetes

k8s 常用命令-kubectl

2022-10-28 23:33:28
670  0 0

管理类

kubectl 工具用法
kubectl 子命令 资源对象类型 资源对象名称 子命令可选参数

查看

查看版本
kubectl version
查看集群node
kubectl get nodes
查看命名空间
kubectl get namespace
查看命名空间下的对象,不加参数--namespace 默认default
kubectl get pod
kubectl get pod --namespace kube-system
查看 deployment
kubectl get deployment
查看pod , node节点详细信息
kubectl describe node 192.168.0.133
kubectl describe pod nginx-a12s
kubectl describe pod nginx-a12s -n kube-system
kubectl get svc #(kubectl get services)
查看pod详情
kubectl describe pod podname
kubectl get pods --all-namespaces
kubectl get pod -o wide
进入pod
kubectl exec -ti <your-pod-name> -n <your-namespace>  -- /bin/sh
同时使用多个yaml文件创建
kubectl create -f a.yaml -f b.yaml -f c.yaml
创建 根据目录下所有yaml yml json文件创建
kubectl create -f 路径
删除 基于yaml
kubectl delete -f a.yaml
删除 所有包含某个label的pod和service
kubectl delete pods,services -l name=*
删除所有pod
kubectl delete pods --all
指定pod中的某个容器执行date命令
kubectl exec podename date -c ** date
通过bash获得pod中某个容器的tty,相当于登录容器
kubectl exec -ti podname -c * /bin/bash
kubectl exec -ti nginx-wbfm4 -- /bin/bash
查看容器输出到stdout的日志
kubectl logs *
跟踪查看容器的日志 相当于tail -f
kubectl logs -f podname -c *
创建或更新资源对象(不存在就创建,存在就更新)
kubectl apply -f app.yaml
pod和本地间复制文件 赋值pod的etc到本地data
kubectl cp nginx:/etc /data
下线或暂停节点
kubectl cordon node1
驱动node节点上的Pod(先设置node为cordon不可调度状态,然后驱逐Pod)
kubectl drain <node name>
维护完后需要将节点设置为可调度
kubectl uncordon <node name>
删除节点
kubectl delete node node1
pod重启-没有yaml文件重启
  使用scale命令
  #kubectl scale deployment {pod} --replicas=0 -n {namespace}
  #kubectl scale deployment {pod} --replicas=1 -n {namespace}

  直接删除重启
  此方式只针对使用的deployment对象,并且重启策略为可以重启,则可以尝试删除重启
  #kubectl delete replicaset {rs_name} -n {namespace}

  使用 -o yaml参数导出Pod模板并重建模板
  #kubectl get pod {podname} -n {namespace} -o yaml | kubectl replace --force -f -
查看所有节点标签
  kubectl  get node --show-labels=true
打标签
  kubectl label nodes master-1 node=master-1
查看污点
kubectl describe nodes master-1 |grep Taints
去除节点污点
kubectl taint node master-3 node-role.kubernetes.io/master-
kubectl输出格式
json格式输出
kubectl get pod -o=json

根据自定义列输出,逗号隔离
kubectl get pod -o=custom-columns=***

从文件获取列名输出
kubectl get pod -o=custom-columns-flie=***

输出jsonpath表达上定义的字段信息
kubectl * -o=jsonpath=*

输出jsonpath表达上定义的字段信息,来源于文件
kubectl * -o=jsonpath-file=*

仅输出资源对象名称
kubectl * -o=name

输出额外信息
kubectl * -o=wide

yaml格式显示结果
kubectl * -o=yaml
kubectl get pod -o=custom-columns=NAME:metadata.name,RSRC:.metadata.resourceVersion

查看etcd是否正确启动
etcdctl cluster-health
......

评论 (0)

点击这里取消回复。

欢迎您 游客  

Copyright © 2025 网站备案号 : 蜀ICP备2022017747号
smarty_hankin 主题. Designed by hankin
主页
页面
  • #1742(无标题)
博主
tang.show
tang.show 管理员
linux、centos、docker 、k8s、mysql等技术相关的总结文档
213 文章 2 评论 202058 浏览
测试
测试