Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No internet connectivity inside docker container running inside kubernetes with weave as networking

I have a kubernetes cluster that is running on AWS EC2 instances and weave as networking(cni). I have disabled the docker networking(ipmask and iptables) as it is managed by weave(to avoid network conflicts).

I have deployed my Jenkins on this cluster as K8s pod and this jenkins uses jenkins kubernetes plugin to spawn dynamic slaves based on pod and container template which I have defined. These slaves container have docker client in it which connects to the host docker engine via docker.sock

So when I run any job in Jenkins it starts a slave and on this it clones a git repo and starts building the Dockerfile present inside the repo.

My sample dockerfile looks like this:

FROM abc:123
RUN yum update

So when container starts building this it tries connecting to redhat repo to update the local repo and fails here. To debug I logged in to this container and try wget/CURL some packages and finds that there is no internet connectivity in this container.

I suspect that while building docker starts intermediate containers and those containers are not managed by weave so they do not have internet connectivity.

Need suggestions.

Related question: Internet connection inside Docker container in Kubernetes

like image 253
Vaibhav Jain Avatar asked Mar 15 '18 12:03

Vaibhav Jain


People also ask

What is weave networking in Kubernetes?

Weave Net provides a network to connect all pods together, implementing the Kubernetes model. Kubernetes uses the Container Network Interface (CNI) to join pods onto Weave Net. Kubernetes implements many network features itself on top of the pod network.

Can Docker containers connect to the Internet?

Connect a container to a network when it starts You can also use the docker run --network=<network-name> option to start a container and immediately connect it to a network.

Can Kubernetes run without internet?

Kubernetes does not need any internet access for normal operation when all required containers and components are provided by the private repository. A good starting point is the Bare Metal offline provisioning guide.

How networking happens in Kubernetes?

Kubernetes networking allows Kubernetes components to communicate with each other and with other applications. The Kubernetes platform is different from other networking platforms because it is based on a flat network structure that eliminates the need to map host ports to container ports.


2 Answers

Ok finally after lot of struggle I find the solution.
So when ever K8s starts a pod it starts a sidecart container whose role is basically to provide network to pod containers.
So while running docker build if I pass it's container ID as network then my intermediate contexts start getting internet connectivity via this container. So changes looks something like this:

docker build -t "some name" --network container:\$(docker ps | grep \$(hostname) | grep k8s_POD | cut -d\" \" -f1) -f infra/docker/Dockerfile .

Hope this helps. :D

like image 52
Vaibhav Jain Avatar answered Sep 17 '22 23:09

Vaibhav Jain


You can try to attach weave networking dynamically as a part of your build job. Is it definitely possible to change active network of container on the flight with weave.

Maybe you will need to use some additional container with Weave Docker Api Proxy or you can use a different way to communicate with Weave network on your nodes.

So, the main idea is just attach your containers where you running builds to the Kubernetes pods network, where you have an external access.

Also, and maybe it will be better, you can create another one Weave virtual network with access to the Internet and attach your contenders to it.

like image 24
Anton Kostenko Avatar answered Sep 19 '22 23:09

Anton Kostenko