DEV Community

Cover image for Understanding Kubernetes Object Management
Akshay Rao
Akshay Rao

Posted on

Understanding Kubernetes Object Management

Introduction

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
PROS

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

CONS

  • 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
metadata:
  name: web-declarative
  annotations:
    site: blog
spec:
 containers:
    - name: web
      image: nginx:1.17.1
Enter fullscreen mode Exit fullscreen mode

Image 2

PROS

  • 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.

CONS

  • 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.

Example:-

Image 3

Image 4

PROS

  • 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.

CONS

  • 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.

Conclusion

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)