Created
January 5, 2017 03:33
-
-
Save rkuzsma/2450c1cfe5b27ae2344c0c1c2c769323 to your computer and use it in GitHub Desktop.
Get external IP address of Kubernetes nodes
This file contains 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
#!/bin/bash | |
kubectl get nodes --selector=kubernetes.io/role!=master -o jsonpath={.items[*].status.addresses[?\(@.type==\"ExternalIP\"\)].address} |
For those using zsh, they need to use quotes around the jsonpath argument, and remove the escape characters:
kubectl get nodes -o jsonpath="{.items[*].status.addresses[?(@.type=='ExternalIP')].address}"
kubectl get nodes -o wide | awk '{print $7}'
is it possible to get this somehow as an environment variable in a deployment?
Like following from the downward API?
- name: K8S_HOST_IP
valueFrom:
fieldRef:
fieldPath: status.hostIP
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The addresses structure has changed:
So now it's
kubectl get nodes --selector=kubernetes.io/role!=master -o jsonpath={.items[*].status.addresses[?\(@.type==\"InternalIP\"\)].address}