Interview Prep/Shell Scripting/find, xargs, jq and yq

How do you update a Kubernetes manifest's image with `yq` using a shell variable?

IntermediateConceptfind, xargs, jq and yq
Answer
export IMAGE="ghcr.io/shack/api:1.4.2"
yq -i '(.spec.template.spec.containers[] | select(.name == "api")).image = strenv(IMAGE)' deploy.yaml

# multi-document file: only Deployments
yq -i '(select(.kind == "Deployment") | .spec.replicas) = 3' all.yaml

# read a value
replicas=$(yq '.spec.replicas' deploy.yaml)

strenv(VAR) reads an exported environment variable as a string, avoiding quoting and injection issues. env(VAR) parses it as YAML (so "123" becomes a number).

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on find, xargs, jq and yq