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

 

 

Check out our latest blogpost


Capacity management: Optimized IT performance through strategic resource management

Operational efficiency and system performance can be increased through strategic capacity management and precise resource planning.
Design Escapes