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

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值