Append to an array

Add the DEBUG env var to the first container

yq -i '.spec.containers[0].env += {"name":"DEBUG","value":"true"}' deployment.yaml

tool
yq15 commands
tags
yq

More yq commands

  • yq -i 'del(.metadata.annotations."kubectl.kubernetes.io/last-applied-configuration")' resource.yaml

    Remove the last-applied-configuration annotation from a manifest

  • yq eval-all 'select(fileIndex==0) * select(fileIndex==1)' base.yaml override.yaml

    Deep-merge override.yaml into base.yaml and print the result

  • yq -o=json '.' config.yaml

    Print a YAML document as JSON

  • cat config.json | yq -P '.'

    Print JSON as readable YAML (-P)

  • yq '.items[] | select(.status.phase == "Running")' pods.yaml

    Select only pods in the Running phase

all 15 yq commands