Save–Logs - anongitmous/k8sShell GitHub Wiki
Save pod and container logs.
[-Containers] <Mtf.Kubernetes.Models.V1K8sContainer[]>
[-BytesLimit <Int32>]
[-Directory <String>]
[-Since <String>]
[-SinceTime <DateTime>]
[-TailLines <Int32>]
[-DoNotCreateDirectories]
[-Follow]
[-Previous]
[-SkipTlsVerify]
[-Timestamps]
[<CommonParameters>]
[-Pods] <Mtf.Kubernetes.Models.V1K8sPod[]>
[-ContainerName <String>]
[-BytesLimit <Int32>]
[-Directory <String>]
[-Since <String>]
[-SinceTime <DateTime>]
[-TailLines <Int32>]
[-DoNotCreateDirectories]
[-Follow]
[-Previous]
[-SkipTlsVerify]
[-Timestamps]
[<CommonParameters>]
For every result of Get–Pods or Get–Containers piped into this cmdlet, save the logs. The log files that are output are named according to the following pattern (if only a pod is specified, then there would be no container name):
YYYY-MM-DDTHH-mm-ss--PODNAME_CONTAINERNAME.log
If there is only a pod, then the pattern is:
YYYY-MM-DDTHH-mm-ss--PODNAME.log
The default behavior is to save the entirety of the logs. This can be modified via one of the -BytesLimit, -Since, -SinceTime, or -TailLines arguments.
The logs are downloaded in parallel.
ℹ️ See A Note about the Examples
1. Download the logs from every pod according to the currently active cluster configuration
- If the
ContainerNameargument is not supplied, then the source pods in this example must have a single container. If not, then the log saving operation will fail for that pod.- Using aliasing, the above can be shortened to
ksgp | kssl
2. Download the logs from every container in every pod according to the currently active cluster configuration
- Using aliasing, the above can be shortened to
ksgp | ksgc | kssl
3. Download the most recent five minutes of logs from every pod according to the currently active cluster configuration
- If the
ContainerNameargument is not supplied, then the source pods in this example must have a single container. If not, then the log saving operation will fail for that pod.- Using aliasing, the above can be shortened to
ksgp | kssl -Since 5m
-Containers
- The container(s) resulting from a call to Get–Containers from which to save logs.
| 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 from which to save logs.
| 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 from which to save logs.
- Specify along with the
-Podsparameter to specify which container from which to save logs 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 |
-BytesLimit
- The maximum bytes of a log to return.
- Defaults to no limit.
| Type: | Int32 |
| Aliases: | |
| Position: | Named |
| Default value: | No Limit |
| Accept pipeline input: | False |
| Accept wildcard characters: | False |
-Directory
- The output directory to use.
| Type: | String |
| Aliases: | |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | False |
| Accept wildcard characters: | False |
-Since
- The relative time in seconds before the current time from which to show logs.
- If this value precedes the time a pod was started, the entire log will be returned.
- If this value is in the future, no log lines will be returned.
- Input format:
- 60 - 60 seconds. integers are interpreted as seconds.
- 60s - 60 seconds
- 10m - 10 minutes
- 1h - 1 hour
- 1d - 1 day
- Only one of
-Sinceor-SinceTimemay be specified.
| Type: | String |
| Aliases: | |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | False |
| Accept wildcard characters: | False |
-SinceTime
- Only return logs after a specific date (RFC3339).
- Defaults to all logs.
- Only one of
-SinceTimeor-Sincemay be used.
| Type: | DateTime |
| Aliases: | |
| Position: | Named |
| Default value: | None |
| Accept pipeline input: | False |
| Accept wildcard characters: | False |
-TailLines
- The number of lines from the end of the logs to show.
- If not specified, logs are shown from the creation of the container or
-Sinceor-SinceTime.
| Type: | Int32 |
| Aliases: | |
| Position: | Named |
| Default value: | No Limit |
| Accept pipeline input: | False |
| Accept wildcard characters: | False |
-DoNotCreateDirectories
- By default, output directories are created.
- Specify this to have the save operation fail if the output directory does not exist.
| Type: | SwitchParameter |
| Aliases: | |
| Position: | Named |
| Default value: | False |
| Accept pipeline input: | False |
| Accept wildcard characters: | False |
-Follow
- If specified, the logs will be saved to a file until stopped via Ctrl-C, the container exits, or the connection is dropped.
| Type: | SwitchParameter |
| Aliases: | |
| Position: | Named |
| Default value: | False |
| Accept pipeline input: | False |
| Accept wildcard characters: | False |
-Previous
- Print the logs for the previous instance of the container in a pod if it exists.
| Type: | SwitchParameter |
| Aliases: | |
| Position: | Named |
| Default value: | False |
| Accept pipeline input: | False |
| Accept wildcard characters: | False |
-SkipTlsVerify
- Skip verifying the identity of the kubelet from which logs are requested.
| Type: | SwitchParameter |
| Aliases: | |
| Position: | Named |
| Default value: | False |
| Accept pipeline input: | False |
| Accept wildcard characters: | False |
-Timestamps
- Add timestamps to each line of log output.
| Type: | SwitchParameter |
| Aliases: | |
| Position: | Named |
| Default value: | False |
| Accept pipeline input: | False |
| Accept wildcard characters: | False |
K8sShell includes the following alias for Save-Logs:
- kssl