Source code of snippets included as screenshots at https://mannymon.medium.com/processing-kubectl-yaml-output-with-yq-bf0dc98ddeab
-
-
Save getsueineko/3b338027176ecea4d22eee71a9b2edb6 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