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-Pods without 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 $null or '') 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 $containers would each have their logs saved.
    • $containers | Start-PortForward
      • The container(s) represented by $containers would be port forwarded to.
    • $containers | Start-KubectlExec
      • The container(s) represented by $containers would be exec'd into.
    • $containers | Invoke-RemoteCommand -Shell '/bin/bash' -ShellFlags '-c' -Command "ls /home"
      • The container(s) represented by $containers would have the ls command run on them and the output returned for each.
    • $containers | Invoke-CopyRemoteToLocal -Source /var/logs -Destination C:/temp -CreateChildDirectory
      • The container(s) represented by $containers would have the contents of each var/log directory copied to the C:\Temp directory.