A Note about the Examples - anongitmous/k8sShell GitHub Wiki
Configuration Assumption
Throughout the documentation of the cmdlets, it is assumed that the cluster configuration functionality as covered here has been enabled.
Therefore, a cmdlet such as Get–Pods will, in its most basic form, be presented as follows:
Get-Pods.
If there were not a cluster configuration active with valid values, then those values would need to be specified explicitly as so:
Get-Pods -KubeConfig <config path> -Context <context to use if no default> -Namespace <namespace to use>.
- If there were a default kube config on the system and a default context, then running
Get-Podswithout any arguments would work with the caveat that it would run against all namespaces.
Examples are Simplified
Additionally, most of the examples are highly simplified in that all filtering of objects has been removed.
For large clusters, running the examples 'as is' could result in many more operations taking place. E.g.
Get-Pods | Get-Containers | Save-Logs
If the namespace were not configured (equivalently, set to$nullor'') this would download every log from every container in every pod in the cluster. Whereas,Get-Pods -ns 'some_namespace' | ? {$_.Name -match 'pod_id'} | Get-Containers | ? {$_.Container -match 'container_id'} | Save-Logs
would only download a small subset of possible container logs.
Results Can Be Reused
- The results of the above expanded query could be saved and reused across a variety of cmdlets that take container objects as pipeline input:
$containers = Get-Pods -ns 'some_namespace' | ? {$_.Name -match 'pod_id'} | Get-Containers | ? {$_.Container -match 'container_id'}$containers | Save-Logs- The container(s) represented by
$containerswould each have their logs saved.
- The container(s) represented by
$containers | Start-PortForward- The container(s) represented by
$containerswould be port forwarded to.
- The container(s) represented by
$containers | Start-KubectlExec- The container(s) represented by
$containerswould be exec'd into.
- The container(s) represented by
$containers | Invoke-RemoteCommand -Shell '/bin/bash' -ShellFlags '-c' -Command "ls /home"- The container(s) represented by
$containerswould have thelscommand run on them and the output returned for each.
- The container(s) represented by
$containers | Invoke-CopyRemoteToLocal -Source /var/logs -Destination C:/temp -CreateChildDirectory- The container(s) represented by
$containerswould have the contents of each var/log directory copied to the C:\Temp directory.
- The container(s) represented by