kubernetes: pods cannot connect to internet

9/3/2019

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
calico
kubernetes
proxy

1 Answer

9/3/2019

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

-- VKR
Source: StackOverflow