how to run kubectl command in java

Viewed 1522

I can run kubectl get secret/rabbitmq-expressmode -n expressmode in shell successfully.

However when I try to run it in java with either ProcessBuilder or Runtime.getRuntime().exec, the error:

Error from server (BadRequest): the server rejected our request for an unknown reason

is thrown out.

What's the possible reason?

2 Answers

I had same issue but resolved by programmatically creating bash file containing kubectl... command I was trying to execute directly.

For example, create bash file and put your kubectl command there (i.e.: some-file.sh). Then try then executing it in bash process running within your java code (bash some-file.sh).

Related