I was going through this exercise for Using Calico network policies to block traffic when I thought that instead of deploying the webserver image using this command:
kubectl run webserver --image=k8s.gcr.io/echoserver:1.10 --replicas=3
I would create a yaml file to deploy the webserver instead. Unfortunately, there was something about my yaml file that preventing things from working. That’s when I came across this trick.
- Step 1: deploy the web server using the kubectl run command.
- Step 2: run the following command to get the YAML back for the deployment
kubectl get deployment webserver --output yaml > webserver.yaml
- Step 3: edit the webserver.yaml file to remove extra lines. For me, I was able to remove:
- the status section
- the annotations section
- the strategy section
And just keep the following lines (note, note formatted properly):
- image: k8s.gcr.io/echoserver:1.10
Now, you do not have to edit the file. But I think this is cleaner than the full version that comes back.
So you can delete the deployment that was the result of the command line and instead build future deployments using the yaml file.