04 | Kubectl

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s