Start–KubectlExec - anongitmous/k8sShell GitHub Wiki

Exec into pods (containers).

Syntax

Start-KubectlExec

[-Containers] <Mtf.Kubernetes.Models.V1K8sContainer[]>
[-KubectlPath <String>]
[-Shell <String>]
[-NoExit]
[<CommonParameters>]

Start-KubectlExec

[-Pods] <Mtf.Kubernetes.Models.V1K8sPod[]>
[-ContainerName <String>]
[-KubectlPath <String>]
[-Shell <String>]
[-NoExit]
[<CommonParameters>]

Description

For every result of Get–Pods or Get–Containers piped into this cmdlet, a console will be opened and the pod will be exec'd into with the console's title set to 'namespace/pod name', or if containers are being used, 'namespace/container name'.

Examples

ℹ️ See A Note about the Examples
⚠️ While the above note about the examples does address this, it cannot be stressed enough that if the below examples are run without making use of any server-side filtering (via field and label selectors) or client-side filtering (via e.g. use of PowerShell's Where-Object), depending upon the cluster size and active namespace, there could be many console windows opened.

1. Exec into every pod

Get-Pods | Start-KubectlExec

  • If the ContainerName argument is not supplied, then the source pods in this example must have a single container. If not, then the exec operation will fail for that pod.
  • Using aliasing, the above can be shortened to
    ksgp | ksske

2. Exec into every container in every pod, overriding the remote shell to invoke

Get-Pods | Get-Containers | Start-KubectlExec -Shell '/bin/sh'

  • Using aliasing, the above can be shortened to
    ksgp | ksgc | ksske -Shell '/bin/sh'

Parameters

-Containers

Type: Mtf.Kubernetes.Models.V1K8sContainer[]
Aliases:
Position: 0
Default value: None
Accept pipeline input: True
Accept wildcard characters: False

-Pods

  • The pod(s) resulting from a call to Get–Pods to exec into.
Type: Mtf.Kubernetes.Models.V1K8sPod[]
Aliases:
Position: 0
Default value: None
Accept pipeline input: True
Accept wildcard characters: False

-ContainerName

  • The name of the container to exec into.
  • Specify along with the -Pods parameter to specify which container to exec into when the pods have more than a single container.
Type: String
Aliases:
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-KubectlPath

  • The full path (if necessary) of the kubectl executable.
Type: String
Aliases:
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Shell

  • The kubectl shell to use (e.g. 'sh' or 'bin/bash'.
Type: String
Aliases: d
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-NoExit

  • Switch parameter for troubleshooting.
  • If kubectl fails to launch, include this flag to prevent the PowerShell hosting window from exiting so that any errors can be seen.
Type: SwitchParameter
Aliases:
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

Notes

K8sShell includes the following alias for Start-KubectlExec:

  • ksske

Related

⚠️ **GitHub.com Fallback** ⚠️