GKE: Determine Anthos on-prem GKE master node and IP address

If you are using Anthos GKE on-premise and need to determine which node of your Admin Cluster is the master, query for the master role.  The label is ‘node-role.kubernetes.io/master’.

$ kubectl get nodes -l node-role.kubernetes.io/master
NAME                                       STATUS   ROLES                  AGE   VERSION
gke-admin-master-adfwa                     Ready    control-plane,master   7d   v1.24.9-gke.100

# using wide will also show External and Internal IP address
$ kubectl get nodes -l node-role.kubernetes.io/maste -o wide

If you want to use this IP address in a script, below are two equivalent commands, one using the built-in JSONPath of kubectl and the other using the jq utility.

# InternalIP using built-in JSONPath
kubectl get nodes -l node-role.kubernetes.io/master -o=custom-columns="IP:.status.addresses[?(@.type=='InternalIP')].address" --no-headers

# InternalIP using jq
kubectl get nodes -l node-role.kubernetes.io/master -o=json | jq -r '.items[0].status.addresses[] | select(.type | contains("InternalIP") ).address'

REFERENCES

github stedolan, jq to filter objects based on contents of key

stackoverflow, how to filter by string in jsonpath

jq utility

jsontostring.com, jsonpath reference

jsonpath.com, online evaluator