I have bunch of Java apps running in Kubernetes. This is mainly legacy code with very big code base. The problem is almost all of the apps uses some third party libraries. It causes Java (or those libraries to be exact) to ignore http_proxy
and https_proxy
environment variables in Docker container. It ignores Java options as well.
Because of big code base and multiple dependencies it's miserable task to rewrite it to use http proxy properly. We reconfigured entire Jsoup related code in one app. That was easy enough to do but we have much more complex apps and even some without source code at all.
So, is there any way to make http proxy system wide AKA transparent to Java? Just force any http/s traffic via proxy.
I've tried numerous tricks and tweaks but nothing. Keep in mind I can't set global rule on k8s node. There are multiple apps which I don't want to use http proxy with.
Any help appreciated.
UPDATE:
Running Java with:
-Dhttp.proxyHost=my_proxy_ip -Dhttp.proxyPort=my_proxy_port
or:
-Djava.net.useSystemProxies=true
unfortunately doesn't work. Hardcoding like so:
System.setProperty("http.proxyHost", "someUrl");
System.setProperty("http.proxyPort", "somePort");
also fails.
This is because there are third party libraries like Jsoup. Unless we configure this library to use proxy it doesn't. Only Java-native http tools are using proxy properly with such settings.
UPDATE 2:
Even not desired I've tried hardcoding proxy in docker demon. That was just desperation and somebody suggested that so I did it just for testing purposes. Apparently all it does is... just setting up http_proxy
environment variable inside each container. So back to beginning unfortunately.
This is clearly wrote in point 2:
2. When you create or start new containers, the environment variables are set automatically within the container.
here: https://docs.docker.com/network/proxy/ but in a hurry I lost half hour to learn this hard way.
Any ideas?