一. 查看集群信息

[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

Logo

开源、云原生的融合云平台

更多推荐