Difference between revisions of "Yq"
		
		
		
		
		
		Jump to navigation
		Jump to search
		
				
		
		
	
|  (Created page with "kubectl get configMap zabbix-server -oyaml | yq eval 'del(.metadata.resourceVersion, .metadata.uid, .metadata.annotations, .metadata.creationTimestamp, .metadata.selfLink, .me...") | |||
| (6 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
| + | ## 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)' - | 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: | Ref: | ||
| - https://stackoverflow.com/questions/61392206/kubectl-export-is-deprecated-any-alternative | - https://stackoverflow.com/questions/61392206/kubectl-export-is-deprecated-any-alternative | ||
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: