Using yq
, you can simply write:
yq -y '.spec.template.spec.containers[0].image = "foo:latest"' pod.yml
Which produces:
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: myapp
name: myapp-deployment
spec:
replicas: 1
template:
spec:
containers:
- name: myapp
image: foo:latest
But I would use kustomize for something like this, as @DavidMaze suggested.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…