I tried Kubernetes Object Management

I tried Kubernetes Object Management

Clock Icon2022.12.05

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

Introduction

Hi, I am Akshay Rao currently working in Annotation. There are three ways to create and manage Kubernetes objects.

  • Imperative commands
  • Imperative object configuration
  • Declarative object configuration
  • We will go through each way one by one.

    Let's start

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


    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.


    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. Thank you

    Share this article

    facebook logohatena logotwitter logo

    © Classmethod, Inc. All rights reserved.