K9s: Shell into Windows containers

Created on 27 May 2020  路  2Comments  路  Source: derailed/k9s






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.

enhancement

Most helpful comment

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.

All 2 comments

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.

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
Was this page helpful?
0 / 5 - 0 ratings

Related issues

andrej-pavlov picture andrej-pavlov  路  3Comments

vasicvuk picture vasicvuk  路  3Comments

ArnaudMsh picture ArnaudMsh  路  3Comments

ctritten picture ctritten  路  3Comments

binarycoded picture binarycoded  路  3Comments