Skip to content

Commit 3871537

Browse files
committed
doc: document the usage of the PodLogsQuerySplitStreams feature
Signed-off-by: Jian Zeng <[email protected]>
1 parent 35e7e1d commit 3871537

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

content/en/docs/concepts/cluster-administration/logging.md

+31
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,37 @@ appending a container name to the command, with a `-c` flag, like so:
7575
kubectl logs counter -c count
7676
```
7777

78+
79+
### Container log streams
80+
81+
{{< feature-state feature_gate_name="PodLogsQuerySplitStreams" >}}
82+
83+
As an alpha feature, the kubelet can split out the logs from the two standard streams produced
84+
by a container: [standard output](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout))
85+
and [standard error](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)).
86+
To use this behavior, you must enable the `PodLogsQuerySplitStreams`
87+
[feature gate](/docs/reference/command-line-tools-reference/feature-gates/).
88+
With that feature gate enabled, Kubernetes {{< skew currentVersion >}} allows access to these
89+
log streams directly via the Pod API. You can fetch a specific stream by specifying the stream name (either `Stdout` or `Stderr`),
90+
using the `stream` query string. You must have access to read the `log` subresource of that Pod.
91+
92+
To demonstrate this feature, you can create a Pod that periodically writes text to both the standard output and error stream.
93+
94+
{{% code_sample file="debug/counter-pod-err.yaml" %}}
95+
96+
To run this pod, use the following command:
97+
98+
```shell
99+
kubectl apply -f https://k8s.io/examples/debug/counter-pod-err.yaml
100+
```
101+
102+
To fetch only the stderr log stream, you can run:
103+
104+
```shell
105+
kubectl get --raw "/api/v1/namespaces/default/pods/counter-err/log?stream=Stderr"
106+
```
107+
108+
78109
See the [`kubectl logs` documentation](/docs/reference/generated/kubectl/kubectl-commands#logs)
79110
for more details.
80111

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: PodLogsQuerySplitStreams
3+
content_type: feature_gate
4+
_build:
5+
list: never
6+
render: false
7+
8+
stages:
9+
- stage: alpha
10+
defaultValue: false
11+
fromVersion: "1.32"
12+
---
13+
Enable fetching specific log streams (either stdout or stderr) from a container's log streams, using the Pod API.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: counter-err
5+
spec:
6+
containers:
7+
- name: count
8+
image: busybox:1.28
9+
args: [/bin/sh, -c,
10+
'i=0; while true; do echo "$i: $(date)"; echo "$i: err" >&2 ; i=$((i+1)); sleep 1; done']

0 commit comments

Comments
 (0)