Kubernetes Imperative Vs Declarative handling

Kubernetes objects like pods, replicaset, statefulset, services, etc.. can be created in Imperative and Declarative mode.

Imperative mode

  • In the imperative mode of creating Kubernetes objects, the objects are created with Kubernetes's kubectl commands.
  • One advantage of imperative mode is we can create and delete objects quickly as it is a single-line command execution
  • In imperative mode, we use  kubectl create

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

# service creation
kubectl create service clusterip linuxdatahub--tcp=80:80
#  Deployment creation
kubectl create deployment data-node --image=<image-name>
#Create jobs
kubectl create job <jobname> --image=<image-name>

Declarative mode:

  • In Declarative mode, the Kubernetes objects are created with a manifest YAML file.
  • Users need to prepare manifest YAML with required mandatory parameters and need to be used with kubectl apply
  • Manifest file content change according to the objects, but the template of the manifest is common, below snippet shows the template


During the course of the tutorial, we will be using both imperative and declarative method

Official Kubernetes doc on imperative and declarative methods can be found here


Search on LinuxDataHub

Leave a Comment