<p>Currently, I obtaine various information from the GoogleCloudPlatform management console screen, but in the future I would like to obtain it using API.
The information obtained is as follows. </p>

<pre><code>Kubernetes Engine&gt;Clusters&gt;Cluster Size
Kubernetes Engine&gt;Workloads&gt;Pods
</code></pre>

<p>Please teach the API corresponding to each information acquisition.</p>

asaka
<p>You need to:</p>

<ol>
<li>install your command line</li>
<li>connect to your project</li>
<li>connect to your cluster</li>
<li>retrieve the number of pod inside your cluster</li>
</ol>

<h2>Install your command line</h2>

<p>You can use your prefered command line or you can use the active cloud shell of your browser (the online command line interface integrated to Google Cloud Platform).</p>

<p>Option A) Using your own command line program, you need to install <a href="https://cloud.google.com/sdk/install" rel="nofollow noreferrer">Google Cloud command (gcloud)</a> on your machine.</p>

<p>Option B) Otherwise if you use the active cloud shell, just click on the active cloud shell button on the top of the page.</p>

<p><a href="https://i.stack.imgur.com/DTfic.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DTfic.jpg" alt="enter image description here"></a></p>

<h2>Connect to your project</h2>

<p>(only for option A)</p>

<ul>
<li>Login to your gcloud platform: <strong><em>gcloud auth login</em></strong></li>
</ul>

<pre>
$ gcloud auth login
Your browser has been opened to visit:

https://accounts.google.com/signin/oauth/oauthchooseaccount?client_id=65654645461.apps.googleusercontent.com&as=yJ_pR_9VSHEGFKSDhzpiw&destination=http%3A%2F%2Flocalhost%3A8085&approval_state=!ChRVVHYTE11IxY2FVbTIxb2xhbTk0SBIfczcxb2xyQ3hfSFVXNEJxcmlYbTVkb21pNVlhOF9CWQ%E2%88%99AJDr988AKKKKKky48vyl43SPBJ-gsNQf8w57Djasdasd&oauthgdpr=1&oauthriskyscope=1&xsrfsig=ChkAASDasdmanZsdasdNF9sDcdEftdfECwCAt5Eg5hcHByb3ZhbF9zdGF0ZRILZGVzdGluYXRpb24ASDfsdf1Eg9vYXV0aHJpc2t5c2NvcGU&flowName=GeneralOAuthFlow
</pre>

<ul>
<li>Connect to your project: <strong><em>gcloud config set project your_project_id</em></strong></li>
</ul>

<pre>$ gcloud projects list

PROJECT_ID              NAME              PROJECT_NUMBER
first-project-265905    My Project        117684542848
second-project-435504   test              895475526863

$ gcloud config set project first-project-265905
</pre>

<h2>Connect to your cluster</h2>

<p>Connected to your project, you need to connect to your cluster.</p>

<p><strong><em>gcloud container clusters get-credentials your_cluster_name</em></strong></p>

<pre>
$ gcloud container clusters list
NAME            LOCATION           MASTER_VERSION  MASTER_IP     MACHINE_TYPE  NODE_VERSION    NUM_NODES  STATUS
test-cluster-1  asia-northeast1-a  1.33.33-gke.24  45.600.23.72  f1-micro      1.13.11-gke.14  3          RUNNING

$ gcloud container clusters get-credentials test-cluster-1
Fetching cluster endpoint and auth data.
kubeconfig entry generated for test-cluster-1.
</pre>

<h2>Retrieve the number of nodes/pods inside your cluster</h2>

<p>inside a given name space run the command</p>

<pre>$ kubectl get nodes
NAME                                          STATUS     ROLES     AGE       VERSION
gke-test-cluster-1-default-pool-d85b49-2545   NotReady       24m       v1.13.11-gke.14
gke-test-cluster-1-default-pool-d85b49-2dr0   NotReady       3h        v1.13.11-gke.14
gke-test-cluster-1-default-pool-d85b49-2f31   NotReady       1d        v1.13.11-gke.14

$ kubectl get pods
NAME      READY     STATUS    RESTARTS   AGE
busybox   0/1       Pending   0          44s
nginx     0/1       Pending   0          1m

</pre>
