Kubernetes: Imperative vs Declarative

TLDR: use Declarative. E.g. Helm charts


Imperative commands

  • objects are created and managed/modified using the CLI
  • all operations are done on live objects


kubectl create ns ghost
kubectl create quota blog –hard=pods=1 -n ghost
kubectl run ghost –image=ghost -n ghost
kubectl expose deployments ghost –port 2368 –type LoadBalancer -n ghost


kubectl create service clusterip foobar --tcp=80:80

To modify any of the objects you can use the kubectl edit command or use any of the convenience wrappers. For example to scale the deployment do:

kubectl scale deployment ghost --replicas 2 -n ghost



Declarative mode

Use a YAML file and run something like:

kubectl apply -f <object>.yaml



More: https://medium.com/bitnami-perspectives/imperative-declarative-and-a-few-kubectl-tricks-9d6deabdde

Leave a Reply

Your email address will not be published. Required fields are marked *