Blogs

  • Home
  • Blog
  • Imperative vs. Declarative in Kubernetes

Imperative vs. Declarative in Kubernetes

Imperative

Description 

  • What to do – step by step process

Simple example in kubernetes 

kubectl run testpod --image=busybox

Advanced Example in kubernetes

kubectl run my-pod --image=busybox --restart=Never --overrides='{ "spec": { "containers": [ { "name": "my-container", "command": [ "/bin/sh", "-c", "echo 'Hello, World!' && sleep 3600" ] } ] } }'

What are the advantages?

  • there is no deeper knowledge in YAML file structure needed to unterstand and operate in the imperative way
  • its fast and easy to do

What is it best for?

  • Certifications such as CKA, where you have to be fast
  • short term testing
  • getting knowledge
  • try-out sessions

 

Declarative

Description 

  • What you want to achieve – what is the goal?

Simple Example in kubernetes

Kubectl apply -f testpod.yaml
Testpod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: testpod
spec:
  containers:
  - name: busybox
    image: busybox

Advanced Example in kubernetes

apiVersion: v1
kind: Pod
metadata:
  name: my-pod
spec:
  restartPolicy: Never
  containers:
  - name: my-container
    image: busybox
    command: ["/bin/sh", "-c", "echo 'Hello, World!' && sleep 3600"]

What are the advantages?

  • gives a better view of what is done
  • the file is like a construction plan, which can be easily transfered to another instance

What is it best for?

  • Production environments for getting a better view of what and who it has been done
  • Complex configuration
  • persistance

 

Author: Maximilian Pfisterer

Check out our latest blogpost


Advanced Kubernetes Operators: Enhancing Automation and Management

At the heart of Kubernetes automation, Operators stand as the technical cornerstone, enhancing cluster efficiency and management through advanced operational mechanisms.

Any Questions?

Please feel free to contact us for any question that is not answered yet. 

We are looking forward to get in contact with you!

Newsletter

Design Escapes

KubeOps GmbH
Hinter Stöck 17
72406 Bisingen
Germany

  • Telefon:

    +49 7433 93724 90

  • Mail:

    This email address is being protected from spambots. You need JavaScript enabled to view it.

Download Area
Certified as

KubeOps GmbH is the owner of the Union trademark KubeOps with the registration number 018305184. 

© KubeOps GmbH. All rights reserved. Subsidiary of