Internet from docker container with Kubernetes

2/14/2018

I setup cntlm as a proxy of my enterprise proxy with the good credentials. It binds on all interface.

It works fine in local with environment variable export

http_proxy=http://127.0.0.1:3128

In a standalone docker environment, I setup the http_proxy with http://172.17.0.1:3128 (which is the ip of docker0). It works as well.

Now I did the same configuration with a kubernetes cluster. And it seems to not work properly. I did a telnet and I am not able to contact cntlm which is installed on the host.

Any idea of what's wrong?

Regards.

-- Samuel Mutel
docker
kubernetes
proxy

1 Answer

2/14/2018

I would like to contact cntlm on the host from a docker container

There are many ways to make a kubernetes pod communicate with an application on the host outside docker / kubernetes:

  1. Use hostNetwork: true and communicate with cntlm on the host from inside the pod:

    kind: Pod
    spec:
      template:
        spec:
          hostNetwork: true
  2. Use kubernetes port-forwarding and forward the cntlm port on the host to a free port inside the pod and access cntlm (on the host) from inside the pod:

    kubectl port-forward <pod name> <cntlm's port on host>:<free port in pod>

    Keep in mind that kubectl port-forward does not support forwarding to a service currently due to this issue.

  3. I recommend this: Containerize cntlm too and deploy it in kubernetes and communicate with it using services in k8s.

-- Vikram Hosakote
Source: StackOverflow