yq commands

15 commands, each with a one-line explanation. Click a command to copy it, or its title for details.

Commands 15 shown

  • yq '.spec.replicas' deployment.yaml

    Extract a value from a YAML file

  • yq -i '.spec.replicas = 3' deployment.yaml

    In-place update of a YAML field

  • yq -o=json deployment.yaml

    Output YAML as JSON for jq processing

  • yq '. *= load("override.yaml")' base.yaml

    Deep-merge a base YAML with an override file

  • yq -s '.' multi.yaml | yq -o=json

    Split a multi-document YAML into a JSON array

  • yq '.spec.replicas' deployment.yaml

    Extract a single field from YAML

  • yq -i '.spec.replicas = 3' deployment.yaml

    Modify YAML file in-place with yq v4

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

    Append an env var to the first container

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

    Remove a specific annotation from YAML

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

    Deep-merge two YAML documents

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

    Output YAML document as JSON

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

    Pretty-print JSON as YAML

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

    Select only Running pods from a list

    debug

  • yq -i '(.spec.template.spec.containers[] | select(.name == "app") | .image) = "myapp:v2.0.0"' deployment.yaml

    Targeted image update for a named container

    ci

  • yq '.metadata.name' manifests/*.yaml

    Extract metadata.name from all YAML files in a directory