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} |
The addresses structure has changed:
"status": {
"addresses": [
{
"address": "172.29.29.29",
"type": "LegacyHostIP"
},
{
"address": "172.29.29.29",
"type": "InternalIP"
},
{
"address": "atomic62",
"type": "Hostname"
}
],
So now it's kubectl get nodes --selector=kubernetes.io/role!=master -o jsonpath={.items[*].status.addresses[?\(@.type==\"InternalIP\"\)].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
It not displaying any output.
[root@master001 ~]# kubectl get nodes -o wide
NAME STATUS ROLES AGE VERSION EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
master001 Ready master 5d v1.9.4 CentOS Linux 7 (Core) 3.10.0-862.el7.x86_64 docker://17.3.2
worker001 Ready node 4d v1.9.4 CentOS Linux 7 (Core) 3.10.0-862.el7.x86_64 docker://17.3.2
worker002 Ready node 7h v1.9.4 CentOS Linux 7 (Core) 3.10.0-862.el7.x86_64 docker://17.3.2