官方文档:https://kubernetes.io/docs/reference/kubectl/overview/

1、从master节点获取node节点的信息

 kubectl   get  node
 
NAME          STATUS     ROLES    AGE    VERSION
10.57.27.19   Ready         11d    v1.14.0
10.57.27.20   Ready         11d    v1.14.0
10.57.27.29   Ready         11d    v1.14.0
10.57.30.10   Ready         11d    v1.14.0
10.57.30.9    Ready         11d    v1.14.0
10.57.33.10   Ready         157d   v1.14.0
10.57.33.11   Ready         157d   v1.14.0
10.57.33.12   Ready         157d   v1.14.0
10.57.33.13   Ready         157d   v1.14.0
10.57.33.14   Ready         88d    v1.14.0
获取某个node
kubectl get   node  10.57.33.36
NAME          STATUS   ROLES    AGE   VERSION
10.57.33.36   Ready       58d   v1.14.0

2、从master节点获取node节点的资源使用情况

NAME          CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%
10.57.27.20   1569m        4%     2419Mi          1%
10.57.27.29   2380m        5%     17834Mi         9%
10.57.30.10   4597m        14%    46666Mi         25%
10.57.30.9    5354m        16%    54264Mi         29%
10.57.33.10   4901m        12%    143382Mi        79%
10.57.33.11   2528m        6%     22361Mi         12%
10.57.33.12   3672m        9%     155182Mi        85%
10.57.33.13   10716m       26%    113048Mi        62%
获取某个node节点的
kubectl top    node  10.57.33.36
NAME          CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%
10.57.33.36   8730m        21%    152082Mi        84%


3、获取集群的信息

kubectl  cluster-info
Kubernetes master is running at https://10.57.33.6:443
Heapster is running at https://10.57.33.6:443/api/v1/namespaces/kube-system/services/heapster/proxy

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

4、获取集群版本信息

kubectl   version

Client Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.0", GitCommit:"641856db18352033a0d96dbc99153fa3b27298e5", GitTreeState:"clean", BuildDate:"2019-03-25T15:53:57Z", GoVersion:"go1.12.1", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.0", GitCommit:"641856db18352033a0d96dbc99153fa3b27298e5", GitTreeState:"clean", BuildDate:"2019-03-25T15:45:25Z", GoVersion:"go1.12.1", Compiler:"gc", Platform:"linux/amd64"}

5、获取目前API接口信息

kubectl   api-resources
NAME                              SHORTNAMES   APIGROUP                       NAMESPACED   KIND
bindings                                                                      true         Binding
componentstatuses                 cs                                          false        ComponentStatus
configmaps                        cm                                          true         ConfigMap
endpoints                         ep                                          true         Endpoints
events                            ev                                          true         Event
limitranges                       limits                                      true         LimitRange
namespaces                        ns                                          false        Namespace
nodes                             no                                          false        Node
persistentvolumeclaims            pvc                                         true         PersistentVolumeClaim
persistentvolumes                 pv                                          false        PersistentVolume
pods                              po                                          true         Pod
podtemplates                                                                  true         PodTemplate
replicationcontrollers            rc                                          true         ReplicationController
resourcequotas                    quota                                       true         ResourceQuota
secrets                                                                       true         Secret
serviceaccounts                   sa                                          true         ServiceAccount
services                          svc                                         true         Service
mutatingwebhookconfigurations                  admissionregistration.k8s.io   false        MutatingWebhookConfiguration
validatingwebhookconfigurations                admissionregistration.k8s.io   false        ValidatingWebhookConfiguration
customresourcedefinitions         crd,crds     apiextensions.k8s.io           false        CustomResourceDefinition
apiservices                                    apiregistration.k8s.io         false        APIService
controllerrevisions                            apps                           true         ControllerRevision
daemonsets                        ds           apps                           true         DaemonSet
deployments                       deploy       apps                           true         Deployment
replicasets                       rs           apps                           true         ReplicaSet
statefulsets                      sts          apps                           true         StatefulSet
tokenreviews                                   authentication.k8s.io          false        TokenReview
localsubjectacce***eviews                      authorization.k8s.io           true         LocalSubjectAcce***eview
selfsubjectacce***eviews                       authorization.k8s.io           false        SelfSubjectAcce***eview
selfsubjectrulesreviews                        authorization.k8s.io           false        SelfSubjectRulesReview
subjectacce***eviews                           authorization.k8s.io           false        SubjectAcce***eview
horizontalpodautoscalers          hpa          autoscaling                    true         HorizontalPodAutoscaler
cronjobs                          cj           batch                          true         CronJob
jobs                                           batch                          true         Job
certificatesigningrequests        csr          certificates.k8s.io            false        CertificateSigningRequest
leases                                         coordination.k8s.io            true         Lease
events                            ev           events.k8s.io                  true         Event
daemonsets                        ds           extensions                     true         DaemonSet
deployments                       deploy       extensions                     true         Deployment
ingresses                         ing          extensions                     true         Ingress
networkpolicies                   netpol       extensions                     true         NetworkPolicy
podsecuritypolicies               psp          extensions                     false        PodSecurityPolicy
replicasets                       rs           extensions                     true         ReplicaSet
redisclusters                     redis        k8s.tongdun.cn                 true         RedisCluster
mpijobs                           mj,mpij      kubeflow.org                   true         MPIJob
turingjupyternotebooks            tjn          ml.tongdun.net                 true         TuringJupyterNotebook
ingresses                         ing          networking.k8s.io              true         Ingress
networkpolicies                   netpol       networking.k8s.io              true         NetworkPolicy
runtimeclasses                                 node.k8s.io                    false        RuntimeClass
poddisruptionbudgets              pdb          policy                         true         PodDisruptionBudget
podsecuritypolicies               psp          policy                         false        PodSecurityPolicy
clusterrolebindings                            rbac.authorization.k8s.io      false        ClusterRoleBinding
clusterroles                                   rbac.authorization.k8s.io      false        ClusterRole
rolebindings                                   rbac.authorization.k8s.io      true         RoleBinding
roles                                          rbac.authorization.k8s.io      true         Role
priorityclasses                   pc           scheduling.k8s.io              false        PriorityClass
csidrivers                                     storage.k8s.io                 false        CSIDriver
csinodes                                       storage.k8s.io                 false        CSINode
storageclasses                    sc           storage.k8s.io                 false        StorageClass
volumeattachments                              storage.k8s.io                 false        VolumeAttachment

6、获取描述信息

 kubectl  describe  node 可以获取所有node节点的信息,但是信息量太大,所以后面+nodeIP查看具体某个node节点的信息
 kubectl  describe  node  10.57.33.36
 Name:               10.57.33.36
Roles:              
Labels:             beta.kubernetes.io/arch=amd64
                    beta.kubernetes.io/os=linux
                    kubernetes.io/arch=amd64
                    kubernetes.io/hostname=10.57.33.36
                    kubernetes.io/os=linux
                    servertype=general
Annotations:        node.alpha.kubernetes.io/ttl: 0
                    volumes.kubernetes.io/controller-managed-attach-detach: true
CreationTimestamp:  Wed, 20 Mar 2019 17:27:43 +0800
Taints:             
Unschedulable:      false
Conditions:
  Type             Status  LastHeartbeatTime                 LastTransitionTime                Reason                       Message
  ----             ------  -----------------                 ------------------                ------                       -------
  MemoryPressure   False   Sat, 18 May 2019 15:00:11 +0800   Wed, 15 May 2019 15:56:33 +0800   KubeletHasSufficientMemory   kubelet has sufficient memory available
  DiskPressure     False   Sat, 18 May 2019 15:00:11 +0800   Wed, 15 May 2019 15:56:33 +0800   KubeletHasNoDiskPressure     kubelet has no disk pressure
  PIDPressure      False   Sat, 18 May 2019 15:00:11 +0800   Wed, 15 May 2019 15:56:33 +0800   KubeletHasSufficientPID      kubelet has sufficient PID available
  Ready            True    Sat, 18 May 2019 15:00:11 +0800   Wed, 15 May 2019 15:56:33 +0800   KubeletReady                 kubelet is posting ready status
Addresses:
  InternalIP:  10.57.33.36
  Hostname:    10.57.33.36
Capacity:
 cpu:                40
 ephemeral-storage:  5718194Mi
 hugepages-2Mi:      0
 memory:             196681076Ki
 pods:               60
Allocatable:
 cpu:                40
 ephemeral-storage:  5516284123127
 hugepages-2Mi:      0
 memory:             184818299Ki
 pods:               60
System Info:
 Machine ID:                 0685cd808d8844c49c943381139b455f
 System UUID:                C4BF926C-C489-03E1-B211-D21D80ED7D1B
 Boot ID:                    d68dbea4-1c3a-4c46-a423-f0c12d62e97b
 Kernel Version:             4.4.138-1.el7.elrepo.x86_64
 OS Image:                   CentOS Linux 7 (Core)
 Operating System:           linux
 Architecture:               amd64
 Container Runtime Version:  docker://18.9.3
 Kubelet Version:            v1.14.0
 Kube-Proxy Version:         v1.14.0
PodCIDR:                     10.57.81.128/26
Non-terminated Pods:         (60 in total)
  Namespace                  Name                                                               CPU Requests  CPU Limits  Memory Requests  Memory Limits  AGE
  ---------                  ----                                                               ------------  ----------  ---------------  -------------  ---
  sentinel                   sentinel-velen-2                                                   100m (0%)     1 (2%)      128Mi (0%)       512Mi (0%)     46h
  sh-inner                sh-inner-dev-shine-inner-531-20190514-6f6dfc45f-sjm9w           250m (0%)     2 (5%)      1Gi (0%)         4000Mi (2%)    2d23h
  sh-inner                sh-inner-smoke-shine-inner-531-20190514-798c7bb657-cxkbf        250m (0%)     2 (5%)      1Gi (0%)         4000Mi (2%)    2d22h
  sim-admin               simadmin-test-common-7bdc7f6658-9tm98                      100m (0%)     2 (5%)      512Mi (0%)       4000Mi (2%)    46h
  spe-asr                 spe-asr-smoke-v0-7-0-20190515-dc8bbc568-dwdcv                   2 (5%)        16 (40%)    4Gi (2%)         16000Mi (8%)   2d22h
  str-server              str-server-smoke-v20190517-7fdd746cc-mcdh6                   500m (1%)     4 (10%)     2Gi (1%)         8000Mi (4%)    21h
  dd-kms                  dd-kms-dev-test-ty-5c666dc6b8-zzr4b                                100m (0%)     4 (10%)     512Mi (0%)       8000Mi (4%)    48m
  datchman                datchman-test-common-5c6fb69f66-bq5c7                              100m (0%)     2 (5%)      512Mi (0%)       4000Mi (2%)    2d20h
Allocated resources:
  (Total limits may be over 100 percent, i.e., overcommitted.)
  Resource           Requests       Limits
  --------           --------       ------
  cpu                19724m (49%)   207 (517%)
  memory             73174Mi (40%)  424296Mi (235%)
  ephemeral-storage  0 (0%)         0 (0%)
Events:              

7 配置node节点的调度策略

   有时候会出现node节点异常等情况,这时候我们就不想将新的容器调度到异常的node节点,可以通过,以下命令对其处理,在关闭其调度策略的过程中,只会影响新的容器调度策略,不会影响已经正常运行的容器。

 cordon         Mark node as unschedulable
 uncordon       Mark node as schedulable
kubectl  cordon  10.57.33.15
node/10.57.33.15 cordoned
10.57.33.15   NotReady,SchedulingDisabled      83d    v1.14.0

kubectl  uncordon  10.57.33.15
node/10.57.33.15 uncordoned

10.57.33.15   NotReady      83d    v1.14.0