Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access other containers of a pod in Kubernetes

When I define multiple containers in a pod/pod template like one container running nginx and another php-fpm, how can they access each other?

Do I have to define some links in the definition (I could not find docs explaining all available config options) or can they each other by default?

If yes what values do I have to put in the config files? I read the sharing a network namespace but I'm not aware of what that really means?

I also could not find any example for that.

like image 749
soupdiver Avatar asked Jun 07 '15 12:06

soupdiver


People also ask

How can containers within a pod communicate with each other?

From a network standpoint, each container within the pod shares the same networking namespace. This gives each container access to the same network resources, such as the pod's IP address. Containers within the same pod can also communicate with each other over localhost.

Can Kubernetes pod run multiple containers?

Pods that run multiple containers that need to work together. A Pod can encapsulate an application composed of multiple co-located containers that are tightly coupled and need to share resources.

Can Kubernetes pods communicate with each other?

Kubernetes defines a network model called the container network interface (CNI), but the actual implementation relies on network plugins. The network plugin is responsible for allocating internet protocol (IP) addresses to pods and enabling pods to communicate with each other within the Kubernetes cluster.

Can a pod have multiple services?

Additional Details about Multi-Containers Pods It's quite common case when several containers in a Pod listen on different ports and you need to expose all this ports. You can use two services or one service with two exposed ports.


1 Answers

All the containers in a pod are bound to the same network namespace.

This means that (a) they all have the same ip address and (b) that localhost is the same across all the containers. In other words, if you have Apache running in one container in a pod and MysQL running in another, you can access MySQL at localhost:3306 from the Apache container (and you could access Apache at localhost:80 from the MySQL container).

While the containers share networking, they do not share filesystems. If you want to share files between containers you will need to make use of volumes. There is a simple volume example here.

like image 107
larsks Avatar answered Sep 19 '22 05:09

larsks