derailed / k9s

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

Shell into Windows containers #735

Open dz-pyps opened 4 years ago

dz-pyps commented 4 years ago




Is your feature request related to a problem? Please describe. At the moment, one can only shell into Linux containers using k9s. Since mixed Kubernetes clusters have gained some traction recently, I think it is a good idea to provide a shell into Windows containers as well.

Describe the solution you'd like The easiest way would be to utilize kubectl exec which provides this functionality out of the box and doesn't require PowerShell installation locally.

Additional context I do understand that even though it sounds simple, there are a lot of caveats we should consider.

mikesmithgh commented 4 years ago

I ended up creating a workaround. If you add the following to ~/.k9s/plugin.yml then you can press w to shell into a windows container.

plugin:
  windows-shell:        
    shortCut: w
    description: "Shell (Windows)"
    scopes:
      - containers
    command: sh
    background: false
    confirm: false
    args:
      - -c
      - "kubectl exec -it -n $NAMESPACE $POD -- cmd.exe"

Only tested on WSL Ubuntu.

jrobertson-insite commented 3 years ago

I went down the plugin route as well but ran in to some weirdness with the plugin as posted by @mjsmith1028. I needed something like this that didn't use "sh", specified the context, and by default goes to powershell since that is in all of our Windows images. This is tested in Terminal in Windows (not in WSL) but would probably work there as well since it only relies on kubectl.

plugin:
  windows-powershell-pod:
    shortCut: w
    description: "Powershell (Windows)"
    scopes:
    - pods
    command: kubectl
    background: false
    confirm: false
    args:
    - exec
    - -it
    - --context
    - $CONTEXT
    - -n
    - $NAMESPACE
    - $NAME
    - --
    - powershell
  windows-powershell-container:
    shortCut: w
    description: "Powershell (Windows)"
    scopes:
    - containers
    command: kubectl
    background: false
    confirm: false
    args:
    - exec
    - -it
    - --context
    - $CONTEXT
    - -n
    - $NAMESPACE
    - $POD
    - --container
    - $NAME
    - --
    - powershell