How to define network in Kubernetes

2/28/2019

I ran docker image with the following command:

sudo docker run -dit --net mynetwork read_and_send_apps_logs:latest

Now I use Kubernetes to run the image. The problem is that I don't know where to define the --net in kubernetes?

Can I define it in the deploy yaml, or when running $kubectl create -f <...> ?

-- Yagel
containers
docker
kubernetes

1 Answer

2/28/2019

Kubernetes doesn't have the same concept of per-application networks.

If you're just using a non-default network to have DNS resolution between containers, you don't really need to do anything. Make sure you create a Service for each pod that receives inbound connections, and Kubernetes provides its own DNS system for you. Instead of Docker-style containername host names, Kubernetes has host names like servicename.namespacename.svc.cluster.local.

If you're trying to partition front-end from back-end services or other things that involve multiple networks, you can set up a NetworkPolicy. (I've never felt like I've needed this but understand the motivation.)

If you're manually setting IP addresses or other very-low-level configuration, don't. Docker can handle this on its own, and you shouldn't be directly using the container IP addresses for anything. Kubernetes's setup is sufficiently different that this won't translate well anyways.

If you're using --net to have one container use another's network namespace, running the two containers in the same Pod might work for you. They will be scheduled on the same node and will share a concept of localhost.

-- David Maze
Source: StackOverflow