• 06.K8S常用命令


    K8S常用命令

    1、label

    添加label语法

    kubectl label nodes =

    删除label语法

    kubectl label nodes -

    修改Label的值
    语法: 需要加上–overwrite参数

    kubectl label nodes = --overwrite

    查看现有node及label

    kubectl get node --show-labels

    2、apply

    创建configmap

    kubectl create configmap nginx-config-face --from-file=/root/services/nginx/nginx_8000.conf

    查看节点状态

    kubectl get pods --all-namespaces -o wide

    发布一个 deployment

    kubectl apply -f https://k8s.io/examples/application/deployment.yaml

    查看发布状态

    kubectl describe deployment nginx-deployment

    获取

    kubectl get deployment

    删除

    kubectl delete deployment nginx-deployment

    3、kubectl常用命令

    查看所有 pod 列表, -n 后跟 namespace, 查看指定的命名空间

    kubectl get pod
    kubectl get pod -n kube  
    kubectl get pod -o wide
    
    • 1
    • 2
    • 3

    查看 RC 和 service 列表, -o wide 查看详细信息

    kubectl get rc,svc
    kubectl get pod,svc -o wide  
    kubectl get pod  -o yaml
    
    • 1
    • 2
    • 3

    显示 Node 的详细信息

    kubectl describe node 192.168.0.212
    
    • 1

    显示 Pod 的详细信息, 特别是查看 pod 无法创建的时候的日志

    kubectl describe pod 
    eg:
    kubectl describe pod redis-master-tqds9
    
    • 1
    • 2
    • 3

    根据 yaml 创建资源, apply 可以重复执行,create 不行

    kubectl create -f pod.yaml
    kubectl apply -f pod.yaml
    
    • 1
    • 2

    基于 pod.yaml 定义的名称删除 pod

    kubectl delete -f pod.yaml 
    
    • 1

    删除所有包含某个 label 的pod 和 service

    kubectl delete pod,svc -l name=
    
    • 1

    删除所有 Pod

    kubectl delete pod --all
    
    • 1

    查看 endpoint 列表

    kubectl get endpoints
    
    • 1

    执行 pod 的 date 命令

    kubectl exec  -- date
    kubectl exec  -- bash
    kubectl exec  -- ping 10.24.51.9
    
    • 1
    • 2
    • 3

    通过bash获得 pod 中某个容器的TTY,相当于登录容器

    kubectl exec -it  -c  -- bash
    eg:
    kubectl exec -it redis-master-cln81 -- bash
    
    • 1
    • 2
    • 3

    查看容器的日志

    kubectl logs 
    kubectl logs -f  # 实时查看日志
    kubectl log    -c  # 若 pod 只有一个容器,可以不加 -c 
    PLAINTEXT 复制 全屏
    
    • 1
    • 2
    • 3
    • 4

    查看注释

    kubectl explain pod
    kubectl explain pod.apiVersion
    
    • 1
    • 2

    创建命名空间“test-env”

    kubectl create namespace test-env
    
    kubectl get namespace #Get a list of namespaces
    
    • 1
    • 2
    • 3
    4、keepalive 命令
    # 检查状态
    systemctl status keepalived
    
    # 查看日志
    journalctl -f -u keepalived
    
    # 查看虚拟ip
    ip a
    
    # 重启
    systemctl restart keepalived.service
    
    systemctl restart docker 
    
    systemctl restart kubelet
    
    
     # nfs
     vim /etc/exports
     
     exportfs -arv
     
    # 启动rpc
    systemctl start rpcbind
    #设置开机启动
    systemctl enable rpcbind
     
    systemctl start nfs
    systemctl enable nfs
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
  • 相关阅读:
    一篇文章讲清楚芯片设计全流程及相关岗位划分
    sql表的相关操作
    Hive【内部表、外部表、临时表、分区表、分桶表】【总结】
    计算机常见I/O操作介绍、I/O操作优化提升程序性能方法(异步I/O、多线程和多进程、非阻塞I/O、I/O多路复用)
    多线程进阶
    influxdb 中得 fields 与 tag 区别总结
    node.js -- 身份认证
    一文读懂身份证ocr识别
    redis故障中出现的缓存击穿、缓存穿透、缓存雪崩?
    【微服务34】分布式事务Seata源码解析二:Seata Server启动时都做了什么【云原生】
  • 原文地址:https://blog.csdn.net/qq_16089135/article/details/134033519