What is Kubectl in Kubernetes?

Published by Aryan on

Kubernetes

Hello my dear friends.

Today I am going to write about another component of Kubernetes. I was learning what is the role of Kubectl in K8s.

Kubectl is another command line interface tool just like Minikube. It is a CLI tool that interacts with Kubernetes cluster via Kubernetes API. It is used to manage K8s clusters.

Some of the operations that Kubectl perform include listing pods, nodes, deployments, master node, creating deployments, etc.

Kubectl is written in Golang and following command can be used to see the same.

$ strings -20 $(which kubectl) | grep Go
  • To view list of nodes
$ kubectl get nodes

NAME       STATUS   ROLES    AGE   VERSION
minikube   Ready    master   5d    v1.18.3
  • To create a new deployment
$ kubectl create deployment webapp --image=nodejscn/node

deployment.apps/webapp created
  • To view list of deployments
$ kubectl get deployments

NAME     READY   UP-TO-DATE   AVAILABLE   AGE
webapp   0/1     1            0           10s
  • To view list of pods
$ kubectl get pods

NAME                     READY   STATUS              RESTARTS   AGE
webapp-d9885cdd5-tlktg   0/1     ContainerCreating   0          18s
  • To see detailed information about pods, nodes, deployments
$ kubectl describe pods

Name:         webapp-d9885cdd5-tlktg
Namespace:    default
Priority:     0
Node:         minikube/172.17.0.2
Start Time:   Sun, 15 Nov 2020 20:35:46 +0530
Labels:       app=webapp
              pod-template-hash=d9885cdd5
Annotations:  <none>
Status:       Pending
IP:           172.18.0.6
IPs:
  IP:           172.18.0.6
Controlled By:  ReplicaSet/webapp-d9885cdd5
Containers:
  node:
    Container ID:   
    Image:          nodejscn/node
    Image ID:       
    Port:           <none>
    Host Port:      <none>
    State:          Waiting
      Reason:       CreateContainerError
    Ready:          False
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-qxk9t (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             False 
  ContainersReady   False 
  PodScheduled      True 
Volumes:
  default-token-qxk9t:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-qxk9t
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason   Age                       From               Message
  ----     ------   ----                      ----               -------
  Warning  Failed   98m (x114 over 2d1h)      kubelet, minikube  Error: ImagePullBackOff
  Normal   Pulling  6m28s (x5074 over 2d22h)  kubelet, minikube  Pulling image "nodejscn/node"
  Normal   Pulled   87s (x5064 over 2d22h)    kubelet, minikube  Successfully pulled image "nodejscn/node"

Aryan

Hey Friends, Thank you for visiting my blog and spending some of your precious time reading it. Myself Aryan who works with a variety of computer technologies. This blog is a write-up of my understanding of various topics after reading different materials about it. I hope that it helps you in some way. Enjoy reading and feel free to connect with me.

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *