I have an app running in an EC2 instance. It starts multiple containers on a network:
docker run --name purple \
--net=treeOfPlums \
--net-alias=purple \
-d treeofplums/purple
docker run --name shiny \
--net=treeOfPlums \
--net-alias=shiny \
-d treeofplums/shiny
In this case the containers purple
and shiny
can communicate because they are both on treeOfPlums
with aliases purple
and shiny
respectively.
I want to deploy this app on K8s. I am using minikube for development. I do not want to use docker-in-docker here, where my main app is a container and it spins up the rest. Instead, I would like to make them all siblings.
My question is, how do I specify the network name and container aliases on that network in a K8s pod?
Using the keywords network
and network-alias
in the deployment yaml won't work. As I understand, containers in a single pod are on one network anyway, so setting an alias will be sufficient too. I am thinking of something like:
spec:
containers:
- name: purple
image: purple
network: treeOfPlums
net-alias: purple
...
The point of pods is so that containers can talk as though they are on localhost. You don't need any additional network tweaks between containers in a pod.
From the docs:
The applications in a pod all use the same network namespace (same IP and port space), and can thus “find” each other and communicate using localhost. Because of this, applications in a pod must coordinate their usage of ports. Each pod has an IP address in a flat shared networking space that has full communication with other physical computers and pods across the network.
The hostname is set to the pod’s Name for the application containers within the pod.
In addition to defining the application containers that run in the pod, the pod specifies a set of shared storage volumes. Volumes enable data to survive container restarts and to be shared among the applications within the pod.
http://kubernetes.io/docs/user-guide/pods/#motivation-for-pods