question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Attach to pod feature

See original GitHub issue

Is your enhancement related to a problem? Please describe

For our current project, we need the ability to attach to the container in a pod to send stdin and read stdout. If I understood correctly, currently there is no way to do it.

Describe the solution you’d like

Implement kubectl attach equivalent the same way as kubectl exec is implemented. The main concern regarding the implementation of such feature is that its’ DSL would clash the existing one for exec (e.g. redirectingInput().redirectingOutput().exec("...")). In my point of view, the DSL should be extended instead of copying, i.e.:

ExecWatch execResult = client.pods().withName("...").inContainer("session").redirectingInput().exec("ls");
AttachWatch attachResult = client.pods().withName("...").inContainer("session").redirectingInput().attach("ls");

Describe alternatives you’ve considered

The alternative way to support such case would be to give a user the ability to use WebSockets directly as it is implemented in official kubernetes-client (though, just to mention, official kubernetes-client has the attach feature). I don’t like such approach, but it may be easier to implement.

Additional context

I’m ready to try to implement this feature by myself after syntax & requirements will be clear.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
shawkinscommented, Aug 15, 2022

I’m trying to attach to the main process (that is actually a shell) of the pod. In that case I can reconnect to the same process (with same previously defined env vars, for example).

Sounds good.

I’m ready to try to implement this feature by myself after syntax & requirements will be clear.

Try adding ExecWatch attach() as a method on https://github.com/fabric8io/kubernetes-client/blob/master/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/dsl/Execable.java

Then add the attach implementation on PodOperationsImpl - you should be able to reuse most of the exec logic.

1reaction
kuzznyacommented, Aug 15, 2022

do you want a new process, or are you trying to attach to the main process of the pod?

I’m trying to attach to the main process (that is actually a shell) of the pod. In that case I can reconnect to the same process (with same previously defined env vars, for example).

App failure or rescheduling results in a new process

Sorry, I didn’t clarify that in my previous message - I meant rescheduling or failure of my app with k8s client, not of a pod with a shell.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Get a Shell to a Running Container - Kubernetes
Attach Handlers to Container Lifecycle Events · Configure a Pod to Use a ConfigMap · Share Process Namespace between Containers in a Pod...
Read more >
kubectl attach - Kubernetes
Attach to a process that is already running inside an existing container. kubectl attach POD -c CONTAINER. Examples. # Get output from running...
Read more >
Attaching a pod to an additional network
Adding a pod to an additional network · 1, Specify the name of the additional network defined by a NetworkAttachmentDefinition object. · 2,...
Read more >
How to K8s: Exec into a Running Kubernetes Pod - MacStadium
To gain access to a Kubernetes pod, we'll have to get a pod's name to target. To do so, we have to call...
Read more >
use 'kubectl exec' to attach pod which has already completed ...
new feature: use 'kubectl exec' to attach pod which has already completed. #56841. Closed. loadwiki opened this issue on Dec 5, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found