derailed / k9s

🐶 Kubernetes CLI To Manage Your Clusters In Style!
https://k9scli.io
Apache License 2.0
27.01k stars 1.69k forks source link

Add support for attaching ephemeral container to a pod #636

Open jeka opened 4 years ago

jeka commented 4 years ago




Is your feature request related to a problem? Please describe. It would be great to add a possibility to attach an ephemeral container to a pod. Yes, it needs quite a recent k8s cluster with feature gate EphemeralContainers enabled but it would be super handy. Bonus points if the image used for the ephemeral container is configurable but the official busybox image will suffice in the beginning.

derailed commented 4 years ago

@jeka Thank you for this issue! I've been indeed watching this feature for a while, still not quite ready for prime time as you've pointed out. However I think you should be able to develop a k9s plugin for this.

Bonus Point: If you have some time and want to send us a PR for the debug plugin we can add it to the plugins dir on this repo.

Something along these lines perhaps??

plugin:
  debug:
    shortCut: Shift-D
    description: Debug
    scopes:
    - po
    command: kubectl
    background: false
    args:
    - alpha
    - debug
    - --container=debug
    - -i
    - --image=busybox
    - $COL-NAME
jeka commented 4 years ago

@derailed OK, I tried to do what you suggested. It mostly works ... with caveats. If you specify a container name, you cant execute command 2nd time because of name duplicate.

error: error updating ephemeral containers: Pod "kubernetes-dashboard-bc446cc64-m6cnt" is invalid: spec.ephemeralContainers[9].name: Duplicate value: "debug"

And you can not attach to the container again as it's not running (if you have exited from it). I guess there are some bits of this feature to be ironed out. if you don't specify a container name its autogenerated and pod spec get bloated over time with ephemeral containers but for debugging purposes it's OK I think.

So, I ended up with the following plugin description:

plugin:
  debug:
    shortCut: Shift-D
    description: Debug
    scopes:
    - po
    command: kubectl
    background: false
    args:
    - alpha
    - debug
    - -n 
    - $NAMESPACE
    - --context
    - $CONTEXT
    - -it
    - --image=busybox
    - $NAME

I also changed $COL-NAME with $NAME. For some reason, $COL-NAME does not return the value of NAME column of currently selected resource but of some other (random?) line in the list and also removed --container parameter.

Btw, can I get an invite to the slack channel? It would be faster for discussing ideas and problems.

derailed commented 4 years ago

@jeka Thank you for looking into it! Great catch on the column mapping!! Bug indeed. I'll fix in the next drop. As for slack you should be able to join here K9slackers Invite

flokli commented 1 year ago

Has there been any discussion around this in Slack? I'd very much like to see some functionality like this added to k9s itself.

matthyx commented 1 year ago

+1 also just being able to list them in the TUI would be nice

thesuperzapper commented 1 year ago

@derailed I have opened a similar (but more specific) request in https://github.com/derailed/k9s/issues/2097, I really think that this feature would be a clear win for k9s, especially as distroless containers become more common, so our current "attach shell" feature becomes less useful.