1

I cannot connect to internet from pods. My kubernetes cluster is behind proxy.
I have already set /env/environment and /etc/systemd/system/docker.service.d/http_proxy.conf, and confirmed that environment variables(http_proxy, https_proxy, HTTP_PROXY, HTTPS_PROXY, no_proxy, NO_PROXY) are correct. But in the pod, when I tried echo $http_proxy, answer is empty. I also tried curl -I https://rubygems.org but it returned curl: (6) Could not resolve host: rubygems.org.
So I think pod doesn't receive environment values correctly or there is something I forget to do what I should do. How should I do to solve it?

I tried to export http_proxy=http://xx.xx.xxx.xxx:xxxx; export https_proxy=....
After that, I tried again curl -I https://rubygems.org and I can received header with 200.

altblanc
  • 69
  • 1
  • 9
  • Possible duplicate of [How to set proxy settings (http\_proxy variables) for kubernetes (v1.11.2) cluster?](https://stackoverflow.com/questions/53173487/how-to-set-proxy-settings-http-proxy-variables-for-kubernetes-v1-11-2-cluste) – char Sep 03 '19 at 08:52
  • `Could not resolve host: rubygems.org` is a DNS issue. You might be connected to internet. Have you tried something like 8.8.8.8? – suren Sep 03 '19 at 13:53
  • I tried, but cannot resolve host. Pod has no `HTTP_PROXY` and `HTTPS_PROXY`, so It seems to use what written in `/etc/resolv.conf`. – altblanc Sep 09 '19 at 02:25

1 Answers1

1

What I see is that you have wrong proxy.conf name. As per official documention the name should be /etc/systemd/system/docker.service.d/http-proxy.confand not /etc/systemd/system/docker.service.d/http_proxy.conf.

Next you add proxies, reload daemon and restart docker, as mentioned in provided in comments another answer

/etc/systemd/system/docker.service.d/http_proxy.conf:

Content:

    [Service]
    Environment="HTTP_PROXY=http://x.x.x:xxxx"
    Environment="HTTPS_PROXY=http://x.x.x.x:xxxx"

# systemctl daemon-reload
# systemctl restart docker

Or, as per @mk_ska answer you can

add http_proxy setting to your Docker machine in order to forward packets from the nested Pod container through the target proxy server.

For Ubuntu based operating system:

Add export http_proxy='http://:' record to the file /etc/default/docker

For Centos based operating system:

Add export http_proxy='http://:' record to the file /etc/sysconfig/docker

Afterwards restart Docker service.

Above will set proxy for all containers what will be used by docker engine

Vit
  • 7,740
  • 15
  • 40
  • 1
    I tried to do this, but cannot solve the problem... In the pod, it seems not to inherit environment variables. Also I found another problem (if I expose `http_proxy`, pods cannot resolve inner server name) so I'm going to close this question and seek another way. Anyway, thank you for your help! ;) – altblanc Sep 09 '19 at 02:22
  • You need to use no_proxy for IP ranges of your cluster. You dont want that traffic routed through your proxy – Michael Quale Dec 06 '19 at 00:08