DEV Community

Cover image for Understanding Kubernetes Object Management
Akshay Rao
Akshay Rao

Posted on


Understanding Kubernetes Object Management


There are three ways to create and manage Kubernetes objects.

  1. Imperative commands
  2. Imperative object configuration
  3. Declarative object configuration

We will go through each way one by one.

Imperative commands

When we want to operate directly on live objects in an cluster we can use the imperative commands, the commands are directly written on the kubectl command line as a argument or flags.
Example:- In this a pod is created using nginx image.
Image 1

  • Imperative way can be used when only a single step is required to do changes in the cluster.


  • don’t incorporate processes for change review.
  • don't offer a change-related audit trail.
  • give just the live sources of records.
  • don't offer a template for making new things.
  • If there are many definition like labels, annotations, names and etc cannot be added at once and it is time consuming.

Imperative object configuration

As we saw in the imperative commands that to add definition to a pod has to done one by one inorder to overcome the difficulty we can use the imperative object configuration in which we can create a yml file, list all the definitions of the pod and run it.
Example:- we are creating a pod name web-declarative from a web-deployment.yml file.

apiVersion: v1
kind: Pod
  name: web-declarative
    site: blog
    - name: web
      image: nginx:1.17.1
Enter fullscreen mode Exit fullscreen mode

Image 2


  • The yml file can be soted in source control system like git.
  • Can review changes before push and audit trails.
  • It can be used as template to create new objects.
  • When compared to declarative object configuration is much simpler to understand.


  • Requires basic understanding of schema.
  • Works best on files not on directories.
  • The next replacement will not take into account changes made to live objects if they are not reflected in configuration files.

Declarative object configuration

When using declarative object configuration, a user manipulates locally stored object configuration files, but the user does not specify the actions to be executed on the files. By using kubectl, create, update, and delete operations are automatically identified for each individual object. This makes it possible to work on directories, where various procedures may be required for various items.


Image 3

Image 4


  • Even if they are not merged back into the configuration files, modifications performed directly to live objects are kept.
  • Declarative object configuration offers better directory support and per-object operation type (new, patch, delete) detection.


  • When outcomes are unexpected, declarative object configuration is more difficult to debug and comprehend.
  • Complex merge and patch processes are produced by using partial updates and diffs.


These are the three ways to operate with kubernetes objects.
I hope this helps you to understand.
Suggest me in comments in which topic in kubernetes you would like to read?
Thank you

Top comments (0)

Timeless DEV post...

Git Concepts I Wish I Knew Years Ago

The most used technology by developers is not Javascript.

It's not Python or HTML.

It hardly even gets mentioned in interviews or listed as a pre-requisite for jobs.

I'm talking about Git and version control of course.

One does not simply learn git