K8s常用运维命令

2024-06-23 15:38

本文主要是介绍K8s常用运维命令,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

一. 查看集群信息

[root@k8s-master ~]# kubectl cluster-info

Kubernetes master is running at http://localhost:8080

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

[root@k8s-master ~]# kubectl cluster-info dump

  

二. 查看各组件状态

[root@k8s-master ~]# kubectl -s http://localhost:8080 get componentstatuses


     

或者

[root@k8s-master ~]# kubectl -s http://172.16.60.220:8080 get componentstatuses

三. GET信息

1) 查看节点 (k8s-master 对应的是 172.18.41.205的主机名)

[root@k8s-master ~]# kubectl get node                                #将命令中的node变为nodes也是可以的

  

[root@k8s-master ~]# kubectl -s http://k8s-master:8080 get node    #将命令中的node变为nodes也是可以的

  

2) 查看pods清单

[root@k8s-master ~]# kubectl get pod                          

  #将命令中的pod变为pods也是可以的                 

  

3) 查看service清单

[root@k8s-master ~]# kubectl get service                                          

#将命令中的service变为services也是可以的

  

或者  (后面的sed表示 打印奇数行)

[root@k8s-master ~]# kubectl get services -o json|grep '"name":'|sed -n '1~2p'

   

  

4) 查看replicationControllers清单 (同理可以将命令中的replicationControllers变为replicationController也是可以的)

[root@k8s-master ~]# kubectl get replicationControllers

  

5) 查看rc和namespace

[root@k8s-master ~]# kubectl get rc,namespace

  

6) 查看pod和svc(和service一样)

[root@k8s-master ~]# kubectl get pods,svc

  

7) 以jison格式输出pod的详细信息.

[root@k8s-master ~]# kubectl get pods

  

注意下面命令中的pods的名称可以通过上面命令查看

[root@k8s-master ~]# kubectl get po nginx-controller-djd1b -o json

{
    "apiVersion": "v1",
    "kind": "Pod",
    "metadata": {
        "annotations": {
            "kubernetes.io/created-by": "{\"kind\":\"SerializedReference\",\"apiVersion\":\"v1\",\"reference\":{\"kind\":\"ReplicationController\",\"namespace\":\"default\",\"name\":\"nginx-controller\",\"uid\":\"50a16131-4d52-11e9-99f2-00163e0e3c31\",\"apiVersion\":\"v1\",\"resourceVersion\":\"3860\"}}\n"
        },
        "creationTimestamp": "2019-03-23T11:03:18Z",
        "generateName": "nginx-controller-",
        "labels": {
            "name": "nginx"
        },
        "name": "nginx-controller-djd1b",
        "namespace": "default",
        "ownerReferences": [
            {
                "apiVersion": "v1",
                "controller": true,
                "kind": "ReplicationController",
                "name": "nginx-controller",
                "uid": "50a16131-4d52-11e9-99f2-00163e0e3c31"
            }
        ],
        "resourceVersion": "8369",
        "selfLink": "/api/v1/namespaces/default/pods/nginx-controller-djd1b",
        "uid": "4387cd87-4d5b-11e9-99f2-00163e0e3c31"
    },
    "spec": {
        "containers": [
            {
                "image": "172.18.41.206:5000/nginx",
                "imagePullPolicy": "Always",
                "name": "nginx",
                "ports": [
                    {
                        "containerPort": 80,
                        "protocol": "TCP"
                    }
                ],
                "resources": {},
                "terminationMessagePath": "/dev/termination-log"
            }
        ],
        "dnsPolicy": "ClusterFirst",
        "nodeName": "172.18.41.207",
        "restartPolicy": "Always",
        "securityContext": {},
        "terminationGracePeriodSeconds": 30
    },
    "status": {
        "conditions": [
            {
                "lastProbeTime": null,
                "lastTransitionTime": "2019-03-23T11:03:18Z",
                "status": "True",
                "type": "Initialized"
            },
            {
                "lastProbeTime": null,
                "lastTransitionTime": "2019-03-23T11:03:18Z",
                "status": "True",
                "type": "Ready"
            },
            {
                "lastProbeTime": null,
                "lastTransitionTime": "2019-03-23T11:03:18Z",
                "status": "True",
                "type": "PodScheduled"
            }
        ],
        "containerStatuses": [
            {
                "containerID": "docker://ca97dceebc3f5a3619b2e83d6d50357eb5beb1abc677a5056442fe6a63b30967",
                "image": "172.18.41.206:5000/nginx",
                "imageID": "docker-pullable://172.18.41.206:5000/nginx@sha256:7734a210432278817f8097acf2f72d20e2ccc7402a0509810c44b3a8bfe0094a",
                "lastState": {},
                "name": "nginx",
                "ready": true,
                "restartCount": 0,
                "state": {
                    "running": {
                        "startedAt": "2019-03-23T11:03:18Z"
                    }
                }
            }
        ],
        "hostIP": "172.18.41.207",
        "phase": "Running",
        "podIP": "192.168.44.3",
        "startTime": "2019-03-23T11:03:18Z"
    }
}

  

还可以输出其它格式和方法(kubectl get -h查看帮助)

[root@k8s-master ~]# kubectl get -h

这篇关于K8s常用运维命令的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1087573

相关文章

nginx -t、nginx -s stop 和 nginx -s reload 命令的详细解析(结合应用场景)

《nginx-t、nginx-sstop和nginx-sreload命令的详细解析(结合应用场景)》本文解析Nginx的-t、-sstop、-sreload命令,分别用于配置语法检... 以下是关于 nginx -t、nginx -s stop 和 nginx -s reload 命令的详细解析,结合实际应

C#连接SQL server数据库命令的基本步骤

《C#连接SQLserver数据库命令的基本步骤》文章讲解了连接SQLServer数据库的步骤,包括引入命名空间、构建连接字符串、使用SqlConnection和SqlCommand执行SQL操作,... 目录建议配合使用:如何下载和安装SQL server数据库-CSDN博客1. 引入必要的命名空间2.

Linux系统性能检测命令详解

《Linux系统性能检测命令详解》本文介绍了Linux系统常用的监控命令(如top、vmstat、iostat、htop等)及其参数功能,涵盖进程状态、内存使用、磁盘I/O、系统负载等多维度资源监控,... 目录toppsuptimevmstatIOStatiotopslabtophtopdstatnmon

PowerShell中15个提升运维效率关键命令实战指南

《PowerShell中15个提升运维效率关键命令实战指南》作为网络安全专业人员的必备技能,PowerShell在系统管理、日志分析、威胁检测和自动化响应方面展现出强大能力,下面我们就来看看15个提升... 目录一、PowerShell在网络安全中的战略价值二、网络安全关键场景命令实战1. 系统安全基线核查

Spring Boot中WebSocket常用使用方法详解

《SpringBoot中WebSocket常用使用方法详解》本文从WebSocket的基础概念出发,详细介绍了SpringBoot集成WebSocket的步骤,并重点讲解了常用的使用方法,包括简单消... 目录一、WebSocket基础概念1.1 什么是WebSocket1.2 WebSocket与HTTP

golang中reflect包的常用方法

《golang中reflect包的常用方法》Go反射reflect包提供类型和值方法,用于获取类型信息、访问字段、调用方法等,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值... 目录reflect包方法总结类型 (Type) 方法值 (Value) 方法reflect包方法总结

C# 比较两个list 之间元素差异的常用方法

《C#比较两个list之间元素差异的常用方法》:本文主要介绍C#比较两个list之间元素差异,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录1. 使用Except方法2. 使用Except的逆操作3. 使用LINQ的Join,GroupJoin

python常用的正则表达式及作用

《python常用的正则表达式及作用》正则表达式是处理字符串的强大工具,Python通过re模块提供正则表达式支持,本文给大家介绍python常用的正则表达式及作用详解,感兴趣的朋友跟随小编一起看看吧... 目录python常用正则表达式及作用基本匹配模式常用正则表达式示例常用量词边界匹配分组和捕获常用re

postgresql数据库基本操作及命令详解

《postgresql数据库基本操作及命令详解》本文介绍了PostgreSQL数据库的基础操作,包括连接、创建、查看数据库,表的增删改查、索引管理、备份恢复及退出命令,适用于数据库管理和开发实践,感兴... 目录1. 连接 PostgreSQL 数据库2. 创建数据库3. 查看当前数据库4. 查看所有数据库

linux重启命令有哪些? 7个实用的Linux系统重启命令汇总

《linux重启命令有哪些?7个实用的Linux系统重启命令汇总》Linux系统提供了多种重启命令,常用的包括shutdown-r、reboot、init6等,不同命令适用于不同场景,本文将详细... 在管理和维护 linux 服务器时,完成系统更新、故障排查或日常维护后,重启系统往往是必不可少的步骤。本文