echo "apiVersion: v1
kind: Node
metadata:
name: host-cluster-control-plane-64j47
labels:
beta.kubernetes.io/arch: amd64
" | yq -o p
Result:
apiVersion = v1
kind = Node
metadata.name = host-cluster-control-plane-64j47
metadata.labels.beta.kubernetes.io/arch = amd64
That's almost what I want. I am looking for the key to get values.
I could use metadata.name
like this:
echo "apiVersion: v1
kind: Node
metadata:
name: host-cluster-control-plane-64j47
labels:
beta.kubernetes.io/arch: amd64
" | yq '.metadata.name'
But the -o p
option of yq
does not quote the key, if needed.
I can't use metadata.labels.beta.kubernetes.io/arch
as key, since the correct syntax is metadata.labels["beta.kubernetes.io/arch"]
.
Is there an automated way to get the keys of a yaml file so that I can use the keys in yq
(or jq
)?
The desired output would be something like this:
apiVersion = v1
kind = Node
metadata.name = host-cluster-control-plane-64j47
metadata.labels["beta.kubernetes.io/arch"] = amd64
I am looking for the valid key, because I want to create a second command line to select these values.
For example:
❯ k get nodes -o yaml | yq '.items[].metadata.labels["beta.kubernetes.io/arch"]'
amd64
amd64
amd64