1 min read | by Jordi Prats
When working with Kubernetes manifests that contain multiple resources, you might need to extract specific objects out of a large document. The yq command-line tool provides powerful filtering capabilities to select and extract individual resources from multi-document YAML files.
In this post, we'll explore how to use yq's select function to do that.
The select function in yq allows us to filter documents based on specific conditions. Here's the command to extract a Secret called config-data
from a multi-document YAML file:
yq 'select(.kind == "Secret" and .metadata.name == "config-data")' ./example.yaml
This command uses a compound filter that matches documents where:
- The kind
field equals "Secret"
- The metadata.name
field equals "config-data"
Breaking down the filter, it looks like this:
select(
.kind == "Secret" and
.metadata.name == "config-data"
)
When applied to a multi-document YAML file, the command will extract only the matching Secret.
Posted on 23/06/2025