• kubectl 常用命令


    kubectl get cs

    [root@master ~]# kubectl get cs
    Warning: v1 ComponentStatus is deprecated in v1.19+
    NAME                 STATUS    MESSAGE             ERROR
    scheduler            Healthy   ok                  
    controller-manager   Healthy   ok                  
    etcd-0               Healthy   {"health":"true"}   
    

    kubectl get deploymen

    
    

    kubectl get pods --all-namespaces

    [root@master ~]# kubectl get pods --all-namespaces
    NAMESPACE     NAME                             READY   STATUS    RESTARTS   AGE
    kube-system   coredns-f9fd979d6-8bqmr          0/1     Pending   0          75m
    kube-system   coredns-f9fd979d6-9hgs9          0/1     Pending   0          75m
    kube-system   etcd-master                      1/1     Running   3          75m
    kube-system   kube-apiserver-master            1/1     Running   3          75m
    kube-system   kube-controller-manager-master   1/1     Running   0          30m
    kube-system   kube-proxy-7k5wr                 1/1     Running   0          75m
    kube-system   kube-proxy-9m8jq                 1/1     Running   0          72m
    kube-system   kube-proxy-bjhk9                 1/1     Running   2          75m
    kube-system   kube-scheduler-master            1/1     Running   0          31m
    ns-elastic    elasticsearch-data-0             0/1     Pending   0          65m
    ns-elastic    elasticsearch-master-0           0/1     Pending   0          65m
    

    kubectl delete pods elasticsearch-data-0

    kubectl get namespace kube-system -o yaml

    只查看kube-system的名称空间信息并以yaml格式显式

    [root@master ~]# kubectl get namespace kube-system -o yaml 
    apiVersion: v1
    kind: Namespace
    metadata:
      creationTimestamp: "2020-10-01T22:32:28Z"
      managedFields:
      - apiVersion: v1
        fieldsType: FieldsV1
        fieldsV1:
          f:status:
            f:phase: {}
        manager: kube-apiserver
        operation: Update
        time: "2020-10-01T22:32:28Z"
      name: kube-system
      resourceVersion: "4"
      selfLink: /api/v1/namespaces/kube-system
      uid: 58592158-9fcd-41f7-9305-c79ee1161468
    spec:
      finalizers:
      - kubernetes
    status:
      phase: Active
    

    只查看kube-system的名称空间信息并以json格式显式

    [root@master ~]# kubectl get namespace kube-system -o json 
    {
        "apiVersion": "v1",
        "kind": "Namespace",
        "metadata": {
            "creationTimestamp": "2020-10-01T22:32:28Z",
            "managedFields": [
                {
                    "apiVersion": "v1",
                    "fieldsType": "FieldsV1",
                    "fieldsV1": {
                        "f:status": {
                            "f:phase": {}
                        }
                    },
                    "manager": "kube-apiserver",
                    "operation": "Update",
                    "time": "2020-10-01T22:32:28Z"
                }
            ],
            "name": "kube-system",
            "resourceVersion": "4",
            "selfLink": "/api/v1/namespaces/kube-system",
            "uid": "58592158-9fcd-41f7-9305-c79ee1161468"
        },
        "spec": {
            "finalizers": [
                "kubernetes"
            ]
        },
        "status": {
            "phase": "Active"
        }
    }
    

    查看指定名称空间的pod(在k8s中容器被封装成pod)

    [root@master ~]# kubectl get pods --all-namespaces
    NAMESPACE     NAME                             READY   STATUS    RESTARTS   AGE
    kube-system   coredns-f9fd979d6-8bqmr          0/1     Pending   0          87m
    kube-system   coredns-f9fd979d6-9hgs9          0/1     Pending   0          87m
    kube-system   etcd-master                      1/1     Running   3          87m
    kube-system   kube-apiserver-master            1/1     Running   3          87m
    kube-system   kube-controller-manager-master   1/1     Running   0          41m
    kube-system   kube-proxy-7k5wr                 1/1     Running   0          86m
    kube-system   kube-proxy-9m8jq                 1/1     Running   0          84m
    kube-system   kube-proxy-bjhk9                 1/1     Running   2          87m
    kube-system   kube-scheduler-master            1/1     Running   0          42m
    ns-elastic    elasticsearch-data-0             0/1     Pending   0          77m
    ns-elastic    elasticsearch-master-0           0/1     Pending   0          77m
    [root@master ~]# kubectl get pods -n ns-elastic
    NAME                     READY   STATUS    RESTARTS   AGE
    elasticsearch-data-0     0/1     Pending   0          77m
    elasticsearch-master-0   0/1     Pending   0          77m
    [root@master ~]# 
    
    

    查看当前集群的deployments控制器

    [root@master ~]# kubectl get deploy -n kube-system -o wide
    NAME      READY   UP-TO-DATE   AVAILABLE   AGE    CONTAINERS   IMAGES                     SELECTOR
    coredns   0/2     2            0           100m   coredns      k8s.gcr.io/coredns:1.7.0   k8s-app=kube-dns
    
    

    查看名称空间,namespace简写形式

    [root@master ~]# kubectl get ns 
    NAME              STATUS   AGE
    default           Active   101m
    kube-node-lease   Active   101m
    kube-public       Active   101m
    kube-system       Active   101m
    ns-elastic        Active   94m
    

    删除资源

    删除名称为"ns-elastic"名称空间,如果想要删除多个名称空间使用空格隔开即可,删除资源时会删除该名称空间下的所有pods资源,因此删除名称空间是很危险的操作,生产环境要谨慎操作

    [root@master ~]# kubectl get ns 
    NAME              STATUS   AGE
    default           Active   104m
    kube-node-lease   Active   104m
    kube-public       Active   104m
    kube-system       Active   104m
    ns-elastic        Active   97m
    [root@master ~]# kubectl delete ns ns-elastic
    namespace "ns-elastic" deleted
    [root@master ~]# kubectl get ns 
    NAME              STATUS   AGE
    default           Active   105m
    kube-node-lease   Active   105m
    kube-public       Active   105m
    kube-system       Active   105m
    
  • 相关阅读:
    如何导入文件夹在项目中
    KVC的学习
    ScrollView学习01
    KVO与KVC整理资料
    KVO监听者
    进程与线程
    解决SQL 2008数据库日志文件过大导致占满整个分区的问题:清理数据库日志文件
    SharePoint开发中发现的SharePoint本身的一些问题
    从十个方面提升SharePoint网站性能
    解决SharePoint2010文档库中新建文档不是保存到文档库而是保存到本地电脑的问题
  • 原文地址:https://www.cnblogs.com/carry00/p/13762413.html
Copyright © 2020-2023  润新知