我有大约 200-300 个 yaml 文件,我想要实现的是仅更改图像:我的几个 yaml 文件中的选项,我有一个可以获取所需 yaml 文件的 shell 脚本,我只想实现改变图像:key only。
解决方案尝试:
使用了一个工具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
此命令的作用是实现更改映像的预期结果,但它还将更改附加到部署文件的所有部分,例如在文件中每个规范的末尾:
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
如何在不将图像附加到部署文件的每个部分的情况下获得所需的结果?