Skip to content

Instantly share code, notes, and snippets.

@montmanu
Last active December 20, 2023 07:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save montmanu/6d9cf430f3fbb9fcd30d0f4f2bb2b849 to your computer and use it in GitHub Desktop.
Save montmanu/6d9cf430f3fbb9fcd30d0f4f2bb2b849 to your computer and use it in GitHub Desktop.
Processing kubectl YAML Output with yq
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 '#.*'
kubectl get ns kube-system -o yaml \
| yq e '.metadata.annotations.istio-injection |= "disabled"' - \
| kubectl apply -f -
kubectl get ns kube-system -o yaml | yq e '.'
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)' -
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 '.'
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