kubernetes imperative commands cheat sheet

The Kubernetes imperative method is one of the approaches used for deploying Kubernetes resources. The imperative mode is the quick way for creating and deleting Kubernetes resources using kubectl commands

Below are the various commands used for creating Kubernetes objects in the imperative mode

Create Deployment

kubectl create deployment <NAME> --image=<imagename>:<tag>

A deployment will be created with <NAME> and image <imagename> will be used

kubectl create deployment linx-deploy --image=nginx:latest

Create Cluster IP Service

kubectl create service clusterip <NAM>--tcp=<port>:<targetport>

A cluster ip service will be created which established connection between target port and the port, and the application in the <targetport> can be accessible via <port>

kubectl create service clusterip hubservice --tcp=9982:80

Create Node Port Serive

kubectl create service nodeport <NAME>--tcp=<clusteripport>:<podport> --node-port=<nodeport>

Here --node-port is an optional parameter, but if specified the value should be between 30000 and 32767

kubectl create service nodeport hubservice --tcp=9982:80 --node-port=30876

Create LoadBalancer Service

kubectl create svc loadbalancer NAME  --tcp=<port>:<targetport>

kubectl create svc loadbalancer datahub-lb --tcp=9276:80

Create Pod

kubectl run <podname> --image=<image>:<tag>

kubectl run datahub-ngnix1 --image=nginx:latest


Create Job

kubectl create job <NAME> --image=<image>:tag

kubectl create job Data-hub-job --image=nginx:latest


Search on LinuxDataHub

1 thought on “kubernetes imperative commands cheat sheet”

Leave a Comment