What is kubectl?

Kubectl is a command line interface for interacting and running commands on Kubernetes clusters.

It is also called as Kube Control.

Example Commands

  • kubectl cluster-info
  • kubectl get nodes

How to create deployment?

kubectl run my-nginx --image nginx

How to get nodes using kubectl?

$ kubectl get nodes

NAME         STATUS     ROLES    AGE   VERSION
kub-master   Ready      master   7m    v1.9.5
kub-node1    Ready      <none>   4m    v1.9.5
kub-node2    Ready      <none>   4m    v1.9.5 

Can we format the output of command of kubectl?

Yes

Use your command with parameter: -o <format>

  • -o yaml
    • This will output the resource definition in YAML format on the screen.
  • -o name
    • Print only the resource name and nothing else
  • -o wide
    • Output in the plain-text format with any additional information
  • -o json
    • Output a JSON formatted API object

Example:

kubectl run my-nginx --image=nginx  --dry-run=client -o yaml

Ok, what if I just want to test my command?

Yes, you can do that using parameter:  –dry-run=client

Using this parameters when command is run, then actual resources are not created, but you just get to know if your command is right.

kubectl run my-nginx --image=nginx  --dry-run=client

You can do one smartness now, you can generate POD definition file automatically using: 

kubectl run my-nginx --image=nginx  --dry-run=client -o yaml
Categories: Devops

Rakesh Kalra

Hello, I am Rakesh. I have more than 15 years of experience working on IT projects, where I have worked on varied complexity of projects and at different levels of roles. I have tried starting my own startups, 3 of those though none of it were successful but gained so much knowledge about business, customers, and the digital world. I love to travel, spend time with my family, and read self-development books.

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published.