Source code of snippets included as screenshots at https://mannymon.medium.com/processing-kubectl-yaml-output-with-yq-bf0dc98ddeab
Last active
December 20, 2023 07:33
-
-
Save montmanu/6d9cf430f3fbb9fcd30d0f4f2bb2b849 to your computer and use it in GitHub Desktop.
Processing kubectl YAML Output with yq
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kubectl get ns kube-system -o yaml \ | |
| yq e '.metadata.annotations.istio-injection lineComment="Configures istio automatic sidecar injection. See https://istio.io/latest/docs/setup/additional-setup/sidecar-injection/"' - \ | |
| grep '#.*' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kubectl get ns kube-system -o yaml \ | |
| yq e '.metadata.annotations.istio-injection |= "disabled"' - \ | |
| kubectl apply -f - |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kubectl get ns kube-system -o yaml | yq e '.' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kubectl get ns kube-system -o yaml | yq e 'del( | |
.metadata.annotations."kubectl.kubernetes.io/last-applied-configuration", | |
.metadata.creationTimestamp, | |
.metadata.managedFields, | |
.metadata.resourceVersion, | |
.metadata.selfLink, | |
.metadata.uid, | |
.status)' - |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kubectl get ns kube-system -o yaml | yq e -j 'del( | |
.metadata.annotations."kubectl.kubernetes.io/last-applied-configuration", | |
.metadata.creationTimestamp, | |
.metadata.managedFields, | |
.metadata.resourceVersion, | |
.metadata.selfLink, | |
.metadata.uid, | |
.status)' - | jq '.' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kubectl get ns kube-system -o yaml \ | |
| yq e '.metadata.annotations.istio-injection |= "enabled"' - \ | |
| kubectl apply -f - |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment