GKE試行（その5：「gcloudコマンド、kubectlコマンドでの状態確認」

# お題
[前回](https://qiita.com/sky0621/items/aadeb53a5be2800066de)、GKE上でのアプリ公開まで出来た。
今回は、クラウドコンソールで確認した「クラスタ」や「ノード」、「ポッド」の状態を gcloud コマンドや kubectl コマンドで確認してみる。

# 環境
[前回](https://qiita.com/sky0621/items/2faf4f7e6b2c9b269945#環境)と同じ。

<pre>
$ kubectl version
Client Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.7", GitCommit:"dd5e1a2978fd0b97d9b78e1564398aeea7e7fe92", GitTreeState:"clean", BuildDate:"2018-04-19T00:05:56Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"9+", GitVersion:"v1.9.7-gke.6", GitCommit:"9b635efce81582e1da13b35a7aa539c0ccb32987", GitTreeState:"clean", BuildDate:"2018-08-16T21:33:47Z", GoVersion:"go1.9.3b4", Compiler:"gc", Platform:"linux/amd64"}
</pre>

# 前提
- 自前でGCPプロジェクトは契約済み
- gcloudをローカルで使える状態になっている

# 実践
クラウドコンソール見るとクラスタの状態、デプロイ、サービスの状態をすぐ確認できる。
けど、せっかくなので gcloud コマンド、kubectlコマンド使っての確認もしてみる。
ポイントは、「クラスタはGKEの概念なので”gcloudコマンド”を使い、ノード、デプロイメント、ポッド、サービスはk8sの概念なので”kubectl”コマンドを使う」こと。

## クラスタの一覧
<pre>
$ gcloud container clusters list
NAME                                   LOCATION           MASTER_VERSION  MASTER_IP      MACHINE_TYPE  NODE_VERSION  NUM_NODES  STATUS
go-webapi-for-gke-study-cluster-1-min  asia-northeast1-a  1.9.7-gke.6     xx.xxx.xx.xxx  f1-micro      1.9.7-gke.6   3          RUNNING
</pre>

## クラスタの詳細
<pre>
$ gcloud container clusters describe go-webapi-for-gke-study-cluster-1-min
addonsConfig:
  networkPolicyConfig:
    disabled: true
clusterIpv4Cidr: 【IP】
createTime: '2018-09-16T03:19:31+00:00'
currentMasterVersion: 1.9.7-gke.6
currentNodeCount: 3
currentNodeVersion: 1.9.7-gke.6
endpoint: 【エンドポイントIP】
initialClusterVersion: 1.9.7-gke.6
instanceGroupUrls:
- https://www.googleapis.com/compute/v1/projects/【プロジェクトID】/zones/asia-northeast1-a/instanceGroupManagers/gke-go-webapi-for-gke-st-default-pool-3b8ab9c5-grp
labelFingerprint: a9dc16a7
legacyAbac: {}
locations:
- asia-northeast1-a
loggingService: logging.googleapis.com
masterAuth:
  clientCertificate:【省略】
  clientKey:【省略】
  clusterCaCertificate:【省略】
monitoringService: monitoring.googleapis.com
name: go-webapi-for-gke-study-cluster-1-min
network: default
networkConfig:
  network: projects/【プロジェクトID】/global/networks/default
  subnetwork: projects/【プロジェクトID】/regions/asia-northeast1/subnetworks/default
nodeConfig:
  diskSizeGb: 10
  diskType: pd-standard
  imageType: COS
  machineType: f1-micro
  oauthScopes:
  - https://www.googleapis.com/auth/devstorage.read_only
  - https://www.googleapis.com/auth/logging.write
  - https://www.googleapis.com/auth/monitoring
  - https://www.googleapis.com/auth/service.management.readonly
  - https://www.googleapis.com/auth/servicecontrol
  - https://www.googleapis.com/auth/trace.append
  - https://www.googleapis.com/auth/compute
  preemptible: true
  serviceAccount: default
nodeIpv4CidrSize: 24
nodePools:
- config:
    diskSizeGb: 10
    diskType: pd-standard
    imageType: COS
    machineType: f1-micro
    oauthScopes:
    - https://www.googleapis.com/auth/devstorage.read_only
    - https://www.googleapis.com/auth/logging.write
    - https://www.googleapis.com/auth/monitoring
    - https://www.googleapis.com/auth/service.management.readonly
    - https://www.googleapis.com/auth/servicecontrol
    - https://www.googleapis.com/auth/trace.append
    - https://www.googleapis.com/auth/compute
    preemptible: true
    serviceAccount: default
  initialNodeCount: 3
  instanceGroupUrls:
  - https://www.googleapis.com/compute/v1/projects/【プロジェクトID】/zones/asia-northeast1-a/instanceGroupManagers/gke-go-webapi-for-gke-st-default-pool-3b8ab9c5-grp
  management:
    autoRepair: true
  name: default-pool
  selfLink: https://container.googleapis.com/v1/projects/【プロジェクトID】/zones/asia-northeast1-a/clusters/go-webapi-for-gke-study-cluster-1-min/nodePools/default-pool
  status: RUNNING
  version: 1.9.7-gke.6
selfLink: https://container.googleapis.com/v1/projects/【プロジェクトID】/zones/asia-northeast1-a/clusters/go-webapi-for-gke-study-cluster-1-min
servicesIpv4Cidr: 10.55.240.0/20
status: RUNNING
subnetwork: default
zone: asia-northeast1-a
</pre>

## ノードの一覧
<pre>
$ kubectl get nodes
NAME                                                  STATUS    ROLES     AGE       VERSION
gke-go-webapi-for-gke-st-default-pool-3b8ab9c5-062c   Ready     ＜none＞   17h       v1.9.7-gke.6
gke-go-webapi-for-gke-st-default-pool-3b8ab9c5-3wzx   Ready     ＜none＞   16h       v1.9.7-gke.6
gke-go-webapi-for-gke-st-default-pool-3b8ab9c5-7tpj   Ready     ＜none＞   17h       v1.9.7-gke.6
</pre>

## ノードの詳細
<pre>
$ kubectl describe node gke-go-webapi-for-gke-st-default-pool-3b8ab9c5-062c
Name:               gke-go-webapi-for-gke-st-default-pool-3b8ab9c5-062c
Roles:              ＜none＞
Labels:             beta.kubernetes.io/arch=amd64
                    beta.kubernetes.io/fluentd-ds-ready=true
                    beta.kubernetes.io/instance-type=f1-micro
                    beta.kubernetes.io/os=linux
                    cloud.google.com/gke-nodepool=default-pool
                    cloud.google.com/gke-preemptible=true
                    failure-domain.beta.kubernetes.io/region=asia-northeast1
                    failure-domain.beta.kubernetes.io/zone=asia-northeast1-a
                    kubernetes.io/hostname=gke-go-webapi-for-gke-st-default-pool-3b8ab9c5-062c
Annotations:        node.alpha.kubernetes.io/ttl=0
                    volumes.kubernetes.io/controller-managed-attach-detach=true
Taints:             ＜none＞
CreationTimestamp:  Sun, 16 Sep 2018 12:21:13 +0900
Conditions:
  Type                 Status  LastHeartbeatTime                 LastTransitionTime                Reason                       Message
  ----                 ------  -----------------                 ------------------                ------                       -------
  KernelDeadlock       False   Mon, 17 Sep 2018 05:24:48 +0900   Sun, 16 Sep 2018 12:20:23 +0900   KernelHasNoDeadlock          kernel has no deadlock
  NetworkUnavailable   False   Sun, 16 Sep 2018 12:21:24 +0900   Sun, 16 Sep 2018 12:21:24 +0900   RouteCreated                 RouteController created a route
  OutOfDisk            False   Mon, 17 Sep 2018 05:24:46 +0900   Sun, 16 Sep 2018 12:21:13 +0900   KubeletHasSufficientDisk     kubelet has sufficient disk space available
  MemoryPressure       False   Mon, 17 Sep 2018 05:24:46 +0900   Sun, 16 Sep 2018 12:21:13 +0900   KubeletHasSufficientMemory   kubelet has sufficient memory available
  DiskPressure         False   Mon, 17 Sep 2018 05:24:46 +0900   Sun, 16 Sep 2018 12:21:13 +0900   KubeletHasNoDiskPressure     kubelet has no disk pressure
  Ready                True    Mon, 17 Sep 2018 05:24:46 +0900   Sun, 16 Sep 2018 12:21:33 +0900   KubeletReady                 kubelet is posting ready status. AppArmor enabled
Addresses:
  InternalIP:  【IP】
  ExternalIP:  【IP】
  Hostname:    gke-go-webapi-for-gke-st-default-pool-3b8ab9c5-062c
Capacity:
 cpu:     1
 memory:  608252Ki
 pods:    110
Allocatable:
 cpu:     940m
 memory:  608252Ki
 pods:    110
System Info:
 Machine ID:                 f56987c738e8859cbef6ac27fb5cf8a3
 System UUID:                F56987C7-38E8-859C-BEF6-AC27FB5CF8A3
 Boot ID:                    383e5637-d3a4-4d6f-9b7f-0a562533ccf2
 Kernel Version:             4.4.111+
 OS Image:                   Container-Optimized OS from Google
 Operating System:           linux
 Architecture:               amd64
 Container Runtime Version:  docker://17.3.2
 Kubelet Version:            v1.9.7-gke.6
 Kube-Proxy Version:         v1.9.7-gke.6
PodCIDR:                     10.52.1.0/24
ExternalID:                  【ID】
Non-terminated Pods:         (4 in total)
  Namespace                  Name                                                              CPU Requests  CPU Limits  Memory Requests  Memory Limits
  ---------                  ----                                                              ------------  ----------  ---------------  -------------
  kube-system                fluentd-gcp-v2.0.17-pdkqp                                         100m (10%)    0 (0%)      200Mi (33%)      300Mi (50%)
  kube-system                kube-dns-5dcfcbf5fb-d6hst                                         260m (27%)    0 (0%)      110Mi (18%)      170Mi (28%)
  kube-system                kube-dns-autoscaler-69c5cbdcdd-w4pqc                              20m (2%)      0 (0%)      10Mi (1%)        0 (0%)
  kube-system                kube-proxy-gke-go-webapi-for-gke-st-default-pool-3b8ab9c5-062c    100m (10%)    0 (0%)      0 (0%)           0 (0%)
Allocated resources:
  (Total limits may be over 100 percent, i.e., overcommitted.)
  CPU Requests  CPU Limits  Memory Requests  Memory Limits
  ------------  ----------  ---------------  -------------
  480m (51%)    0 (0%)      320Mi (53%)      470Mi (79%)
Events:         ＜none＞
</pre>

## ポッドの一覧
<pre>
$ kubectl get pods
NAME                                              READY     STATUS    RESTARTS   AGE
go-webapi-for-gke-study-server-747447689b-m5kw5   1/1       Running   0          11h
</pre>

## ポッドの詳細
<pre>
$ kubectl describe pods go-webapi-for-gke-study-server-747447689b-m5kw5
Name:           go-webapi-for-gke-study-server-747447689b-m5kw5
Namespace:      default
Node:           gke-go-webapi-for-gke-st-default-pool-3b8ab9c5-3wzx/10.146.0.2
Start Time:     Sun, 16 Sep 2018 18:12:31 +0900
Labels:         pod-template-hash=3030032456
                run=go-webapi-for-gke-study-server
Annotations:    kubernetes.io/limit-ranger=LimitRanger plugin set: cpu request for container go-webapi-for-gke-study-server
Status:         Running
IP:             【IP】
Controlled By:  ReplicaSet/go-webapi-for-gke-study-server-747447689b
Containers:
  go-webapi-for-gke-study-server:
    Container ID:   docker://cc9f476e0e97637c726921b481d48905e0b6587c198dc651d61fd6b9bbfe2a67
    Image:          gcr.io/【プロジェクトID】/go-webapi-for-gke-study@sha256:4d1897773110c4ed095fd43d6f08d946c2a9692245cbdf653a689c2dd64e3419
    Image ID:       docker-pullable://gcr.io/【プロジェクトID】/go-webapi-for-gke-study@sha256:4d1897773110c4ed095fd43d6f08d946c2a9692245cbdf653a689c2dd64e3419
    Port:           80/TCP
    State:          Running
      Started:      Sun, 16 Sep 2018 18:12:35 +0900
    Ready:          True
    Restart Count:  0
    Requests:
      cpu:        100m
    Environment:  ＜none＞
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-54k74 (ro)
Conditions:
  Type           Status
  Initialized    True 
  Ready          True 
  PodScheduled   True 
Volumes:
  default-token-54k74:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-54k74
    Optional:    false
QoS Class:       Burstable
Node-Selectors:  ＜none＞
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:          ＜none＞
</pre>

## デプロイメントの一覧
<pre>
$ kubectl get deployments
NAME                             DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
go-webapi-for-gke-study-server   1         1         1            1           11h
</pre>

## デプロイメントの詳細
<pre>
$ kubectl describe deployments go-webapi-for-gke-study-server
Name:                   go-webapi-for-gke-study-server
Namespace:              default
CreationTimestamp:      Sun, 16 Sep 2018 18:12:31 +0900
Labels:                 run=go-webapi-for-gke-study-server
Annotations:            deployment.kubernetes.io/revision=1
Selector:               run=go-webapi-for-gke-study-server
Replicas:               1 desired | 1 updated | 1 total | 1 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  1 max unavailable, 1 max surge
Pod Template:
  Labels:  run=go-webapi-for-gke-study-server
  Containers:
   go-webapi-for-gke-study-server:
    Image:        gcr.io/【プロジェクトID】/go-webapi-for-gke-study@sha256:4d1897773110c4ed095fd43d6f08d946c2a9692245cbdf653a689c2dd64e3419
    Port:         80/TCP
    Environment:  ＜none＞
    Mounts:       ＜none＞
  Volumes:        ＜none＞
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
OldReplicaSets:  ＜none＞
NewReplicaSet:   go-webapi-for-gke-study-server-747447689b (1/1 replicas created)
Events:          ＜none＞
</pre>

## サービスの一覧
<pre>
$ kubectl get services
NAME                             TYPE           CLUSTER-IP     EXTERNAL-IP      PORT(S)        AGE
go-webapi-for-gke-study-server   LoadBalancer   xx.xx.xxx.xx   xx.xxx.xxx.xxx   80:30180/TCP   1h
kubernetes                       ClusterIP      xx.xx.xxx.x    ＜none＞          443/TCP        17h
</pre>

## サービスの詳細
<pre>
$ kubectl describe services go-webapi-for-gke-study-server
Name:                     go-webapi-for-gke-study-server
Namespace:                default
Labels:                   run=go-webapi-for-gke-study-server
Annotations:              ＜none＞
Selector:                 run=go-webapi-for-gke-study-server
Type:                     LoadBalancer
IP:                       xx.xx.xxx.xx
LoadBalancer Ingress:     xx.xxx.xxx.xxx
Port:                     ＜unset＞  80/TCP
TargetPort:               80/TCP
NodePort:                 ＜unset＞  30180/TCP
Endpoints:                xx.xx.x.x:80
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   ＜none＞
</pre>