Hèctor M.C.
Hèctor M.C.

Reputation: 115

Communicate different pods using Podman

I am deploying several Pods using podman-compose. To do so, each pod has its own definition in a podman-compose.yaml file that I execute in rootless mode (so all containers in a Pod coexist in the same host/IP). However, I would like to make able a container in a Pod to reach a service exposed by a container in another pod.

I know Kubernetes has the Service object that let pods communicate between them. But I don't want to use K8S...

So my question is: Is there any 'equivalent' or workaround I could use to reach such a communication between pods? Not only in the Podman ecosystem, but in the Linux's one.

Ideally, I would like to use a DNS that lets containers resolve the IP of other containers in other pods. Should I use my machine (where all pods are running) DNS to proxy requests between pods? And more importantly, is this a good practice?

Sorry if the answer is pretty obvios, I am new in the IT world.

Anyway, thank you all in advance!

Upvotes: 4

Views: 4718

Answers (2)

gregloscombe
gregloscombe

Reputation: 99

Create a network and have all the pods use that network on start. Then if you use --name to name the pods, be able to use that name as the DNS entry from others.

Eg

podman network create $NETWORK_NAME

podman pod create --name $POD1 --network $NETWORK_NAME

podman pod create --name $POD2 --network $NETWORK_NAME

podman run -it --detach --pod $POD1 --name $CONTAINER1 --network $NETWORK_NAME image_name

podman run -it --detach --pod $POD2 --name $CONTAINER2 --network $NETWORK_NAME image_name

now if you were curling from CONTAINER2, you could use curl http://$POD1 and it would resolve to the IP (private ip on the network created) for that POD.

If you dont want to use pods, just remove all pod create and --pod flags to podman run, and instead use $CONTAINER1 or $CONTAINER2 to talk to the other containers in the same network.

With this, you dont need to expose a load of ports, and have your containers communicate to the host and back to the exposed port. Just reference them by pod / container name.

Upvotes: 2

Hèctor M.C.
Hèctor M.C.

Reputation: 115

Finally, I found out in the containers organization the Podman's dnsname plugin that makes possible the pod to pod resolution by using its DNS gateway.

Upvotes: 1

Related Questions