Kubernetes: Declarative vs Imperative (Nginx Example on Minikube)

In this post, I am going to run a Nginx example on Minikube in two ways: 1. declarative: kubectl apply -f [yaml] 2. imperative: kubectl create & expose declarative: kubectl apply -f [yaml] With a declarative way, you can define the resources as yamls and apply them. This is preferable in a long run, but could be tedious if you just want to run it as a test. % cat deploy.yaml apiVersion: apps/v1 kind: Deployment metadata: labels: app: nginx name: nginx spec: replicas: 1 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - image: nginx name: nginx % cat service.yaml apiVersion: v1 kind: Service metadata: labels: app: nginx name: nginx spec: ports: - port: 80 proto...