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

9/18/2018

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.

-- Jeff
kubernetes

3 Answers

5/18/2020

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.

-- mr haven
Source: StackOverflow

9/19/2018

Containers in pod are isolated from each other except that they share volume and network namespace. So you would not be able to execute command from one container into another. However, you could expose the commands in container through APIs

-- Amit
Source: StackOverflow

9/18/2018

In general, no, you can't do this in Kubernetes (or in plain Docker). You should either move the two interconnected things into the same container, or wrap some sort of network service around the thing you're trying to call (and then probably put it in a separate pod with a separate service in front of it).

There might be something you could do if you set up a service account, installed a Kubernetes API sidecar container, and used the Kubernetes API to do the equivalent of kubectl exec, but I'd consider this a solution of last resort.

-- David Maze
Source: StackOverflow