Invoke–RemoteCommand - anongitmous/k8sShell GitHub Wiki
Exececute commands in remote pods (containers).
[-Container] <Mtf.Kubernetes.Models.V1K8sContainer>
[-Shell <String>]
[-ShellFlags <String>]
[-Command <String>]
[-Separator]
[<K8sShellCommonParameters>]
[<CommonParameters>]
[-Pod] <Mtf.Kubernetes.Models.V1K8sPod>
[-ContainerName <String>]
[-Shell <String>]
[-ShellFlags <String>]
[-Command <String>]
[-Separator]
[<K8sShellCommonParameters>]
[<CommonParameters>]
[-PodName] <String>
[-ContainerName <String>]
[-Shell <String>]
[-ShellFlags <String>]
[-Command <String>]
[-Separator]
[<K8sShellCommonParameters>]
[<CommonParameters>]
Runs the command specified by the -Command parameter on each pod or container passed in either via the pipeline or as one of the parameters of -Pod, -PodName, -Container.
ℹ️ See A Note about the Examples
1. Get the environment variables from every container on every pod according to the active cluster configuration with a separator between each
- Using aliasing, the above can be shortened to
ksgp | ksgc | ksirc -Command 'printenv' -Separator
2. Print the contents of the /home directory on every container in every pod according to the active cluster configuration with a separator between each
Get-Pods | Get-Containers | Invoke-RemoteCommand -Shell '/bin/sh' -ShellFlags '-c' -Command "ls -R /home" -Separator
- If the target containers don't have the Bourne shell on them, then the command will fail
- Using aliasing, the above can be shortened to
ksgp | ksgc | ksirc -Command 'pwd' -Shell '/bin/sh' -ShellFlags '-c' -Command "ls -R /home" -Separator
3. Print the disk space usage on every container in every pod according to the active cluster configuration with a separator between each
Get-Pods | Get-Containers | Invoke-RemoteCommand -Shell '/bin/sh' -ShellFlags '-c' -Command 'df -h' -Separator
- If the target containers don't have the Bourne shell on them, then the command will fail
- Using aliasing, the above can be shortened to
ksgp | ksgc | ksirc -Shell '/bin/sh' -ShellFlags '-c' -Command 'df -h' -Separator
-Container
- The container resulting from a call to Get–Containers to execute the command on.
| Type: | Mtf.Kubernetes.Models.V1K8sContainer |
| Aliases: | |
| Position: | 0 |
| Default value: | None |
| Accept pipeline input: | True |
| Accept wildcard characters: | False |
-Pod
- The pod resulting from a call to Get–Pods to execute the command on.
| Type: | Mtf.Kubernetes.Models.V1K8sPod |
| Aliases: | |
| Position: | 0 |
| Default value: | None |
| Accept pipeline input: | True |
| Accept wildcard characters: | False |
-PodName
- The name of the pod to execute the command on.
| Type: | String |
| Aliases: | |
| Position: | 0 |
| Default value: | None |
| Accept pipeline input: | False |
| Accept wildcard characters: | False |
-ContainerName
- The name of the container to execute the command on.
- Specify along with the
-Podsor-PodNameparameter to specify which container to execute the command on 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 |
-Shell
- The shell to use (e.g. 'sh' or 'bin/bash').
| Type: | String |
| Aliases: | |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | False |
| Accept wildcard characters: | False |
-ShellFlags
- The flag(s) to pass to the shell e.g. '-c'.
| Type: | String |
| Aliases: | |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | False |
| Accept wildcard characters: | False |
-Command
- The command to run remotely.
| Type: | String |
| Aliases: | |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | False |
| Accept wildcard characters: | False |
-Separator
- When running a command that generates output against multiple pods or containers, specify this switch so that the output of each will be demarcated.
| Type: | SwitchParameter |
| Aliases: | |
| Position: | Named |
| Default value: | False |
| Accept pipeline input: | False |
| Accept wildcard characters: | False |
K8sShell includes the following alias for Invoke-RemoteCommand:
- ksirc
Which commands can work without specifying the
-Shelland/or-ShellFlagsarguments is unknown to the author.
Commands such asprintenvwork without specifying either the-Shellor-ShellFlagsarguments.
If a command doesn't work, then typically supplying one of/bin/bashor/bin/shto-Shellalong with-ShellFlags -cworks.