Skip to content

Instantly share code, notes, and snippets.

@leitu
Last active February 5, 2019 03:15
Show Gist options
  • Save leitu/5c590e5cef2815ff0911c63760fff8f7 to your computer and use it in GitHub Desktop.
Save leitu/5c590e5cef2815ff0911c63760fff8f7 to your computer and use it in GitHub Desktop.
k8s tricks
# List pods which has CONSUL_HOST
kubectl get pods -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.containers[*].env[?(@.name=="CONSUL_HOST")].value}{"\n"}{end}' | awk ' NF==2 {print $0} '
# List deployment which has CONSUL_HOST
kubectl get deployment -o jsonpath="{range .items[*]}{.metadata.name}{'\t'}{.spec.template.spec.containers[*].env[*].name}{'\n'}{end}" | grep "CONSUL_HOST"
# Patch deployment env
kubectl patch deployment xyz-deployment -p '{"spec":{"template":{"spec":{"containers":[{"name":"xyz", "env":[{"name":"HTTP_PROXY", "value":"xyz-proxy.exampe.com"}]}]}}}}}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment