Difference between revisions of "Yq"
Jump to navigation
Jump to search
(One intermediate revision by the same user not shown) | |||
Line 4: | Line 4: | ||
tar xf yq_linux_amd64.tar.gz | tar xf yq_linux_amd64.tar.gz | ||
sudo cp yq_linux_amd64 /usr/local/bin/yq | sudo cp yq_linux_amd64 /usr/local/bin/yq | ||
+ | ``` | ||
+ | |||
+ | ## kubectl | ||
+ | ``` | ||
+ | ip=$(kubectl get svc foo -o yaml | yq .spec.clusterIP) | ||
``` | ``` | ||
Latest revision as of 02:50, 17 June 2023
Install
curl -LO https://github.com/mikefarah/yq/releases/download/v4.34.1/yq_linux_amd64.tar.gz tar xf yq_linux_amd64.tar.gz sudo cp yq_linux_amd64 /usr/local/bin/yq
kubectl
ip=$(kubectl get svc foo -o yaml | yq .spec.clusterIP)
https://mikefarah.gitbook.io/yq/usage/tips-and-tricks
kubectl get configMap zabbix-server -oyaml | yq eval 'del(.metadata.resourceVersion, .metadata.uid, .metadata.annotations, .metadata.creationTimestamp, .metadata.selfLink, .metadata.managedFields)' -
https://github.com/mikefarah/yq
Dump all
mkdir -p tmp cd tmp for OBJ in $(kubectl api-resources --verbs=list --namespaced -o name) do for DEF in $(kubectl get --show-kind --ignore-not-found $OBJ -o name) do mkdir -p $(dirname $DEF) echo $DEF kubectl get $DEF -o yaml \ | yq eval 'del(.metadata.resourceVersion, .metadata.uid, .metadata.annotations, .metadata.creationTimestamp, .metadata.selfLink, .metadata.managedFields)' - > $DEF.yaml done
env vars
https://mikefarah.gitbook.io/yq/operators/env-variable-operators
yq '(.. | select(tag == "!!str")) |= envsubst(nu, ff)' text.yqenv
Ref: