Declarative vs interactive configuration in k8s

Most time in Kubernetes (aka k8s) we can use the command kubectl to start a deployment.

But in production environment we would better use the declarative configuration such as YAML to define a resource, and start the deployment from that YAML. This is b/c the declarative configuration is easier for version control.

For instance, we can start the deployment using this command,

 $ kubectl run demo --image=cloudnatived/demo:hello --port=8888
$ kubectl port-forward demo 9999:8888
$ curl --head http://localhost:9999

Instead we would do it better by generating a config file, which is controlled via version systems such as Git.

 $ kubectl run demo --image=cloudnatived/demo:hello --port=8888 --dry-run -o yaml  > deploy.yaml
$ kubectl apply -f deploy.yaml
pod/demo created

Hence this is the content in deploy.yaml:

 apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: demo
name: demo
spec:
containers:
- image: cloudnatived/demo:hello
name: demo
ports:
- containerPort: 8888
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}

Everyone can change the deployment. But with a good version control, we can avoid many conflicts.