How to attach a interactive shell in Kubernetes using Python Client

2/20/2017

I am trying to understand on how we can start a interactive shell on a desired container using Kubernetes client-python API.

I found that we can use connect_get_namespaced_pod_exec to run individual commands.

Is there any way we can start a bash session on the desired pod and do somestuff specifically on the pod(I am using Docker Container)

Any help is most welcome.

-- kt14
kubernetes
python
shell

1 Answer

2/20/2017

from reading the tests I'd guess that the linked documentation already holds your answer. Use /bin/bash as command and send any further commands through the stdin stream.

Invokation should be done with:

api.connect_get_namespaced_pod_exec('pod',
                                   'namespace',
                                    command='/bin/bash'
                                    stderr=True,
                                    stdin=True,
                                    stdout=True,
                                    tty=True)

The related kubectl exec --tty ... client code is implemented the same way and could be used as a reference too.

-- pagid
Source: StackOverflow