I have around 200-300 yaml files lying around and What I am trying to achieve is to change only the image: option in few of my yaml files, I have a shell script which can get the required yaml files, and I just want to achieve changing the image: key only.
Solution Tried:
Used a tool yq v4:
for i in ${deployment[@]}
do
yq eval '( select(.spec.template.spec.containers[0].image |= "gcr.io/myrepo/mynginx:1.2.3"' deployment-$i.yaml
done
What this command does is it achieves the desired result of changing the image, but it also appends the changes on the all the parts of deployment file which is for example at the end of every spec in the file:
apiVersion: apps/v1
kind: Deployment
metadata:
name: portal-1
spec:
selector:
matchLabels:
component: portal-1
role: ui
replicas: 1
template:
metadata:
labels:
component: reactportal
role: ui
spec:
containers:
- name: portal
image: gcr.io/myrepo/mynginx:4.52 <<< Desired CHange Happens Here >>>
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
nginx.ingress.kubernetes.io/enable-cors: "false"
nginx.ingress.kubernetes.io/cors-allow-origin: "https://example.com"
name: portal-ingress
spec:
rules:
- host: mydomain.com
http:
paths:
- backend:
serviceName: portal-svc
servicePort: 80
path: /(.*)
template: <<<< THIS IS ALSO GETTING APPENDED >>>
spec:
containers:
- image: gcr.io/myrepo/mynginx:1.2.3
How to achieve the desired result without appending the image on every part of the deployment file?
所有评论(0)