How to get the port number of the Server IP address of a k8s cluster using the info of the kubeconfig file
clusterName="kind-kind"
kubectl config view -o json | \
jq '.clusters[] | select(.name=="'$clusterName'").cluster.server' | \
sed -e 's,^.*:,:,g' -e 's,.*:\([0-9]*\).*,\1,g'
50211
References
- Bash query to extract the URL info: https://stackoverflow.com/questions/6174220/parse-url-in-shell-script/6174447#6174447
- JQ play: https://jqplay.org/
- JQ Manual and doc: https://stedolan.github.io/jq/manual/