Search code examples
kubernetesproxyconfiguration

How to configure proxy in kubernetes to pull images?


I have an installation of kubernetes, which contains only helm, kube apps , contanerd.io. Docker is not installed. I have internet-connection only throw proxy. I am trying to pool longhorn containers with help of helm. but it is not working.Export proxy in .bashrc of /root/.bashrc readed, but not used. I am working from root only. Proxy config in bashrc

http_proxy=http://proxy.example.com
https_proxy=http://proxy.example.com
HTTP_PROXY=http://proxy.example.com
HTTPS_PROXY=http://proxy.example.com

All the time i have to write proxy to make command work. Like

 https_proxy=http://proxy.example.com helm install longhorn/longhorn --name longhorn --namespace longhorn-system

But this is not working when everything is installed into the kuber. There are I have an error Failed to pull and image from every longhorn container.

What is wrong with my proxy configuration? How to configure proxy on kubernetes correctly to pool images from the internet?


Solution

  • As I understand from your configuration, you didn't configure the containerd runtime proxy settings. Because K8s pull images using containerd runtime. If your PCs are behind the proxy, you should always configure the app settings if it doesn't directly use proxy system settings (e.g. docker, containerd, etc.)

    Run on terminal:

    sudo mkdir -p /etc/systemd/system/containerd.service.d
    sudo touch /etc/systemd/system/containerd.service.d/http-proxy.conf
    nano /etc/systemd/system/containerd.service.d/http-proxy.conf
    

    Copy and paste into the http-proxy.conf:

    [Service]
    Environment="HTTP_PROXY=http://proxy.example.com"
    Environment="HTTPS_PROXY=http://proxy.example.com"
    Environment="NO_PROXY=localhost"
    

    Then restart containerd service:

    sudo systemctl daemon-reload
    sudo systemctl restart containerd
    sudo systemctl show --property=Environment containerd