Kubernetes – Imperative commands – part 1 – simplifying concepts

Hi All,
Greetings for the day!!!
Lets continue discussing Kubernetes – Today Kubernetes Imperative CMDLETs
Take away from this article
- What are Kubernetes Imperative CMDLEts
- What prerequisites required to use Kubernetes imperative CMDLETs
- Imperative CMDLETs for Kubernetes cluster
- Imperative CMDLETs Kubernetes objects
- Imperative CMDLETs Kubernetes Nodes
What are Kubernetes Imperative commands
- Imperative commands are the CMDLETs used to create , update, delete Kubernetes objects on the Kubernetes cluster built into the KUBECTL command line tool
- To deploy application on the Kubernetes cluster
Prerequisites
- We need Kubernetes cluster
- To practice or for development purpose we can use minikube utility for setting up Kubernetes cluster locally
- Kubernetes – Setting up kubernetes cluster for development on Windows 10 box using minikube
- Kubernetes simplifying: Setting up local environment – creating Kubernetes cluster locally (helps in Interview Preparation) – Kubernetes for beginners
- We need kubectl command line utility, which actually interacts with Kubernetes cluster
- Understanding of Yaml file – for creating Kubernetes object
Local development cluster
- Here I have setup my local Kubernetes cluster using minikube
- Start the minikube
minikube start
- Know the details of Kubernetes commands – using -h option
- Syntax : kubectl <command-name> -h
- Example :
#get the help on kubectl get command / parameter
kubectl get -h
Imperative CMDLET for verifying KubeCtl installation
- We can verify if kubectl command line utility is successfully installed or not by using “version” attribute to kubectl CMDLET as
kubectl version

Imperative CMDLETs for Kubernetes cluster
- To get cluster information
- Shows the address of control plane
kubectl cluster-info
- To get more detailed information about cluster using dump parameter
- This option is used for debugging purpose and to analyse the cluster problems
- By default it prints all information on console
- We can specify directory path using –output parameter, in this case Kubernetes put all files in specified directory path
kubectl cluster-info dump
- To have dump details in files and in directory
kubectl cluster-info dump --output-directory "C:\\Prasham\\Articles\\Kubernetes\\Imperative CMDLETS\\dump"


- To know the Api Versions on the server
kubectl api-versions
General Kubernetes objects CMDLETs
- What are Kubernetes objects – for details please have a look our article – Kubernetes – Objects – simplifying concepts
- Creating Kubernetes object with specification in Yaml / JSON file
- Syntax – kubectl create -f <kubernetes object yaml specification file path>
- Examples:
kubectl create -f "C:\Prasham\Articles\Kubernetes\Imperative CMDLETS\YAML files\knoweldgejunction_pod.yaml"

- Delete kubernetes object – using delete object
- Syntax – kubectl delete <Kubernetes object>
- Examples:
kubectl delete deployment/nginx
- Get one or more object / resources using get parameter to kubectl CMDLET- print basic information about object
- Syntax – kubectl get
[(-o|--output=)json|yaml|object name | resource name
- Examples:
- Syntax – kubectl get
#list all pods in cluster
kubectl get pods
#list all pods with details in cluster
kubectl get pods -o wide
# List deployments in JSON output format, in the "v1" version of the "apps" API group
kubectl get -f pod.yaml -o json

#To get the multiple objects at time - separated by ","
kubectl get rc,services
Get very detailed information about one or more object / resources using describe parameter to kubectl CMDLET
kubectl describe pod <pod-name>
To get the yaml specification of any Kubernetes object
kubectl get <object-name> <object-value> -o yaml
Here,
<object-name> like - pod , deployment, service, ingress
Example -
kubectl get pod nginx -o yaml
CMDLETs for Nodes
- To get all labels of node
kubectl get nodes <node name> --show-labels
Example:
kubectl get nodes node01 --show-labels

- Apply a label to nodes
kubectl label nodes <node name> <labelname>=<labelvalue>
Example:
kubectl label nodes KnowledgeJunction-Mode01 color=blue
Thanks for reading the article !!! Please feel free to discuss in case any issues / suggestions / thoughts / questions !!!
HAVE A GREAT TIME AHEAD !!!
You must log in to post a comment.