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
- etc.
And just keep the following lines (note, note formatted properly):
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
run: webserver
name: webserver
namespace: default
spec:
replicas: 3
selector:
matchLabels:
run: webserver
template:
metadata:
labels:
run: webserver
spec:
containers:
- image: k8s.gcr.io/echoserver:1.10
name: webserver
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.