I would like to patch all container templates in a Kubernetes deployment with a single kubectl patch command, without having to know their name. Is that possible?
I know I am able to achieve the replacement through awk, sed, jq and kubectl replace, but I would favour something like a [*] in the expression...
Patch command for a certain container spec
kubectl patch deployment mydeployment -p '{"spec":{"template":{"spec":{"containers":[{"name":"myname","imagePullPolicy":"Always"}]}}}}'
Example Deployment
apiVersion: extensions/v1beta1
kind: Deployment
spec:
replicas: 1
template:
spec:
containers:
- image: example.com/my/fancyimage:latest
imagePullPolicy: Never
name: myname
dnsPolicy: ClusterFirst
restartPolicy: Always