Kubectl JSONPath expression to obtain cluster.server property based on current-context

10/24/2019

I'd like to use kubectl with only jsonpath to obtain the current cluster address. I've tried the following, and many permutations of it, but this doesn't seem to work.

kubectl config view -o jsonpath='{.clusters[?($.current-context)].cluster.server}'

Is this possible using only jsonpath?

-- cewood
json-path-expression
jsonpath
kubectl
kubernetes

1 Answer

10/24/2019

You can use the --minify flag:

--minify=false: Remove all information not used by current-context from the output

And then filter the server field from the current context output:

kubectl config view --minify -o jsonpath='{.clusters[].cluster.server}'
-- Eduardo Baitello
Source: StackOverflow