derailed / k9s

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

We would like the ability to copy/paste the kubectl commands #2827

Open scphantm opened 1 month ago

scphantm commented 1 month ago




Is your feature request related to a problem? Please describe. I work in an enterprise environment and work with many different colleagues with issues. Its really annoying when i'm looking at something and trying to get my co-worker to see what i'm seeing. I then have to spend time in the kubectl manual to remember the equivalent commands, then copy and paste stuff out of k9s like pod names, etc, etc, to put together a kubectl command in a text editor that i can paste to my co-worker so they can see what i see. The problem also exists in reverse, a co-worker will send me a kubectl command in the course of debugging something and i have to create a new session, log into it, so i can paste the command and see that output. Then i have to figure out how to get to that screen from within k9s.

Describe the solution you'd like for example, if i am watching a tail of a log file, and i want someone else to see the see the same log, i would like to be able to hit a hot key and get a pop up screen that shows me the equivalent kubectl and oc commands and some way to copy either/or (we have a hybrid environment). Then share that with my co-worker for them to paste and see.

It would also work in reverse. If i hit the hot key, and paste a kubectl or oc command back into the pop up box, overwriting the command that was there by default, k9s then would pop to the k9s equivalent screen.

Describe alternatives you've considered I haven't found one.

KevinGimbel commented 1 month ago

Interesting use case. From what I can tell this seems like a lot of work to get going, if possible at all, since the code would somehow need to map kubectl commands to k9s views - as far as I can tell such a mapping doesn't exist.

As an alternative - at least for the k9s side - you could write plugins to copy kubectl commands.

You could put the following in a plugins.yaml file (my config file is ~/.config/k9s/plugins.yaml):

plugins:
  logs-kubectl-cmd:
    shortCut: Ctrl-L
    confirm: false
    description: Copy kubectl logs command to clipboard
    scopes:
      - pods
    background: true
    command: bash
    args:
      - -c
      - "echo kubectl logs $COL-NAME -n $NAMESPACE | pbcopy"

This would copy the string "kubectl logs $COL-NAME -n $NAMESPACE" to your keyboard when you hit CTRL + L while active on a pod in k9s.

Assumes you have pbcopy installed which is pre-installed on MacOS I think, for Linux there should be similar commands. The documentation for plugins can be found here https://k9scli.io/topics/plugins/