1

I want to create a pod with the python client SDK (similar to kubectl run) that gives me results like the below:

kubectl run --rm --image $IMAGE --overrides="$OVERRIDES" --generator=run-pod/v1 -ti "$POD"

Any good examples? I can see some examples which use exec https://github.com/kubernetes-client/python/blob/master/examples/pod_exec.py but this requires to create the pod first and run exec, but does not run "Interactive Terminal" as the -ti flags in kubectl run.

The code below works only with sending remote command but not with interactive terminal even if we run command=['/bin/bash'] which shows the output as below.

    try:    
        #resp = stream(api_instance.connect_post_namespaced_pod_exec, podname, namespace='default', stderr=True, stdin=True, stdout=True, tty=True)
        stream(api_instance.connect_get_namespaced_pod_exec, podname, namespace='default', stderr=True, stdin=False, stdout=True, tty=False)
    except ApiException as e:
        print("Exception when calling CoreV1Api->connect_get_namespaced_pod_exec: %s\n" % e)
    print(f"Pod created - cannot exec")

enter image description here

mohab
  • 78
  • 10
  • Why do you need the interactive terminal; can you just have the thing you want the pod to do be its `command:`? What's the image you included in the question? – David Maze May 29 '20 at 20:17
  • am building a script for troubleshooting that requires an interactive terminal. running a set of commands is not what am looking for. – mohab May 29 '20 at 20:53

1 Answers1

0

I got this to work here using pseudo terminal. still having some issues after exiting the terminal.

I got it to work here. Still having some issues after exiting the terminal. https://github.com/mohatb/python/blob/master/examples/exec_tty

mohab
  • 78
  • 10