Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 439
cewood Avatar asked Feb 27 '26 07:02

cewood


1 Answers

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}'
like image 200
Eduardo Baitello Avatar answered Mar 02 '26 14:03

Eduardo Baitello



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!