Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kubernetes: Call command in another containers which are in same pod

Tags:

kubernetes

Is there any approach that one container can call command in another container? The containers are in the same pod.

I need many command line tools which are shipped as image as well as in packages. But I don’t want to install all of them into one container because of some concerns.

like image 289
Jeff Avatar asked Sep 18 '18 11:09

Jeff


People also ask

How do you communicate between two containers in a pod?

Multiple containers in the same Pod share the same IP address. They can communicate with each other by addressing localhost . For example, if a container in a Pod wants to reach another container in the same Pod on port 8080, it can use the address localhost:8080 .

Can two containers running in a same pod ping each other?

Containers on same pod act as if they are on the same machine. You can ping them using localhost:port itself. Every container in a pod shares the same IP. You can `ping localhost` inside a pod.

Can two containers use the same port in a pod?

Surprisingly or not, neither Docker nor Podman support exposing multiple containers on the same host's port right out of the box. Example: docker-compose failing scenario with "Service specifies a port on the host. If multiple containers for this service are created on a single host, the port will clash."

Can Kubernetes pods talk to each other?

The Kubernetes model for connecting containersKubernetes assumes that pods can communicate with other pods, regardless of which host they land on. Kubernetes gives every pod its own cluster-private IP address, so you do not need to explicitly create links between pods or map container ports to host ports.


1 Answers

This is very possible as long as you have k8s v1.17+. You must enable shareProcessNamespace: true and then all the container processes are available to other containers in the same pod.

Here are the docs, have a look.

like image 150
mr haven Avatar answered Oct 14 '22 20:10

mr haven