Part 16: GCP/Kubernetes: Hands on with kubernetes Cluster.

In this post, we will see few kubernetes commands to start with.

It will help us to manage K8s/Kubernetes CLuster on any of the Cloud platforms like GCP, AWS, Azure, etc.

 

1. Get the list of all nodes.

saketalwar2@cloudshell:~ (second-abacus-334712)$ kubectl get nodes
NAME                                       STATUS   ROLES    AGE   VERSION
gke-cluster-1-default-pool-1cdaa2b9-33g0   Ready       46m   v1.21.5-gke.1302
gke-cluster-1-default-pool-1cdaa2b9-65kf   Ready       46m   v1.21.5-gke.1302
gke-cluster-1-default-pool-1cdaa2b9-hhf4   Ready       46m   v1.21.5-gke.1302
saketalwar2@cloudshell:~ (second-abacus-334712)$

 

2. Get Cluster Server Information

saketalwar2@cloudshell:~ (second-abacus-334712)$ kubectl cluster-info
Kubernetes control plane is running at https://34.136.229.132
GLBCDefaultBackend is running at https://34.136.229.132/api/v1/namespaces/kube-system/services/default-http-backend:http/proxy
KubeDNS is running at https://34.136.229.132/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Metrics-server is running at https://34.136.229.132/api/v1/namespaces/kube-system/services/https:metrics-server:/proxy

 

3. Check our Kubernetes CLuster Information/Configuration.

aketalwar2@cloudshell:~ (second-abacus-334712)$ kubectl config view
apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: DATA+OMITTED
    server: https://34.136.229.132
  name: gke_second-abacus-334712_us-central1-c_cluster-1
contexts:
- context:
    cluster: gke_second-abacus-334712_us-central1-c_cluster-1
    user: gke_second-abacus-334712_us-central1-c_cluster-1
  name: gke_second-abacus-334712_us-central1-c_cluster-1
current-context: gke_second-abacus-334712_us-central1-c_cluster-1
kind: Config
preferences: {}
users:
- name: gke_second-abacus-334712_us-central1-c_cluster-1
  user:
    auth-provider:
      config:
        access-token: ya29.a0ARrdaM8l-3du7NakfSSNG_90P1MLYBs5XBFxwTGJ6NhocKUg1aDOKMiBu-g7aZOG6owLV-24qyTTODRQQvKKv3uXjvi8o8hpHCsce74HXNSxEGknLCejFcgUyTxcN6cTo_3sCbaEaDea--RPWWt1asOLlq0Dym_bFOhgeoaiYBZ7LP5bLEqU10vfYdnQ4HcFszzVa9QnYaunNAacpPqNG53r9NUepJ4vkR6JuJGvyaC53AHsBCJnPNlKyIZTPkTy2tJr828
        cmd-args: config config-helper --format=json
        cmd-path: /usr/lib/google-cloud-sdk/bin/gcloud
        expiry: "2022-01-07T07:55:57Z"
        expiry-key: '{.credential.token_expiry}'
        token-key: '{.credential.access_token}'
      name: gcp
saketalwar2@cloudshell:~ (second-abacus-334712)$

 

4. Get the number of pods running.

saketalwar2@cloudshell:~ (second-abacus-334712)$ kubectl get pods
No resources found in default namespace.

 

5. Check out Kubectl version.

saketalwar2@cloudshell:~ (second-abacus-334712)$ kubectl version
Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.4", GitCommit:"b695d79d4f967c403a96986f1750a35eb75e75f1", GitTreeState:"clean", BuildDate:"2021-11-17T15:48:33Z", GoVersion:"go1.16.10", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.5-gke.1302", GitCommit:"639f3a74abf258418493e9b75f2f98a08da29733", GitTreeState:"clean", BuildDate:"2021-10-21T21:35:48Z", GoVersion:"go1.16.7b7", Compiler:"gc", Platform:"linux/amd64"}
saketalwar2@cloudshell:~ (second-abacus-334712)$

 

6. To see all API resources.

saketalwar2@cloudshell:~ (second-abacus-334712)$ kubectl api-resources
NAME                              SHORTNAMES   APIVERSION                             NAMESPACED   KIND
bindings                                       v1                                     true         Binding
componentstatuses                 cs           v1                                     false        ComponentStatus
configmaps                        cm           v1                                     true         ConfigMap
endpoints                         ep           v1                                     true         Endpoints
events                            ev           v1                                     true         Event
limitranges                       limits       v1                                     true         LimitRange
namespaces                        ns           v1                                     false        Namespace

 

7. To list all services.

saketalwar2@cloudshell:~ (second-abacus-334712)$ kubectl get all
NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.8.0.1             443/TCP   134m

### From all namespaces
saketalwar2@cloudshell:~ (second-abacus-334712)$ kubectl get all --all-namespaces
NAMESPACE     NAME                                                      READY   STATUS    RESTARTS   AGE
kube-system   pod/event-exporter-gke-5479fd58c8-httgs                   2/2     Running   0          133m
kube-system   pod/fluentbit-gke-k6h9w                                   2/2     Running   0          133m
kube-system   pod/fluentbit-gke-rrpds                                   2/2     Running   0          133m

 

8. To see all APIs versions.

saketalwar2@cloudshell:~ (second-abacus-334712)$ kubectl api-versions
admissionregistration.k8s.io/v1
admissionregistration.k8s.io/v1beta1
apiextensions.k8s.io/v1
apiextensions.k8s.io/v1beta1
apiregistration.k8s.io/v1
apiregistration.k8s.io/v1beta1
apps/v1
authentication.k8s.io/v1

 

9. Check out the usage of nodes.

 
saketalwar2@cloudshell:~ (second-abacus-334712)$ kubectl top node
NAME                                       CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%
gke-cluster-1-default-pool-1cdaa2b9-33g0   52m          5%     566Mi           20%
gke-cluster-1-default-pool-1cdaa2b9-65kf   51m          5%     542Mi           19%
gke-cluster-1-default-pool-1cdaa2b9-hhf4   92m          9%     590Mi           20%
saketalwar2@cloudshell:~ (second-abacus-334712)$

In the next post, we will see how to deploy pod on the GCP cluster nodes, and get this working.

Till now you have an idea of how to deploy K8s/Kubernetes on GCP and become familier with kubectl command

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments