Skip to content

Commit 3105290

Browse files
arybolovlevqmonnet
authored andcommitted
docs: add Gateway API Access logs example
Signed-off-by: Aleksandr Rybolovlev <aleksandr.rybolovlev@proton.me>
1 parent 890b179 commit 3105290

3 files changed

Lines changed: 159 additions & 0 deletions

File tree

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
.. only:: not (epub or latex or html)
2+
3+
WARNING: You are looking at unreleased Cilium documentation.
4+
Please use the official rendered version released here:
5+
https://docs.cilium.io
6+
7+
.. _gs_gateway_access_logs:
8+
9+
***********
10+
Access Logs
11+
***********
12+
13+
This example builds on the previous :ref:`gs_gateway_http` and configures `Envoy
14+
access logs`__ for Gateways managed by Cilium Gateway API.
15+
16+
Access logging is managed via the ``spec.telemetry.accessLogs`` field within a
17+
``CiliumGatewayClassConfig`` resource. Since this configuration is referenced by
18+
``GatewayClass`` resource via ``spec.parametersRef``, any settings you define here will automatically
19+
apply to all Gateways using that specific Gateway Class.
20+
21+
Cilium configures Envoy to write access logs to stdout.
22+
23+
Configuration Options
24+
=====================
25+
26+
When configuring access logs, the ``format`` field is required. You can
27+
customize the log output using the following parameters:
28+
29+
* ``format`` (Required): Defines the log output type. Supported values
30+
are ``Text`` or ``JSON``.
31+
32+
* ``text`` (Optional): A custom Envoy text format string. If you select
33+
``format: Text`` but leave this field empty, Cilium falls back to the
34+
`default Envoy text format`__.
35+
36+
* ``json`` (Optional): A key-value map linking your custom JSON field
37+
names to Envoy format operators. If you select ``format: JSON`` but leave
38+
this field empty, Cilium applies a pre-configured JSON template that
39+
mirrors the information from the default Envoy text format.
40+
41+
.. note::
42+
This default JSON mapping is provided by Cilium, not by Envoy's
43+
built-in defaults.
44+
45+
* ``targets`` (Optional): Specifies the traffic type to log. Supported
46+
values are ``HTTP`` and ``TCP`` (which includes TLS passthrough). If
47+
omitted, Cilium defaults to logging ``HTTP`` traffic only.
48+
49+
Custom Cilium formatters
50+
========================
51+
52+
In addition to standard Envoy operators, Cilium provides two Gateway-specific
53+
formatters to help you identify the source of the traffic:
54+
55+
* ``%CILIUM_GATEWAY_NAMESPACE%`` resolves to the namespace of the Gateway.
56+
57+
* ``%CILIUM_GATEWAY_NAME%`` resolves to the name of the Gateway.
58+
59+
For a complete list of all other available format operators,
60+
please refer to the official Envoy access log substitution `formatter documentation`__.
61+
62+
Deploy a Gateway with access logs
63+
=================================
64+
65+
Create a ``CiliumGatewayClassConfig`` that enables JSON access logs for HTTP
66+
traffic:
67+
68+
.. code-block:: yaml
69+
70+
apiVersion: cilium.io/v2alpha1
71+
kind: CiliumGatewayClassConfig
72+
metadata:
73+
name: cilium
74+
namespace: default
75+
spec:
76+
telemetry:
77+
accessLogs:
78+
- format: JSON
79+
json:
80+
gateway: "%CILIUM_GATEWAY_NAMESPACE%/%CILIUM_GATEWAY_NAME%"
81+
start_time: "%START_TIME%"
82+
method: "%REQUEST_HEADER(:METHOD)%"
83+
path: "%REQUEST_HEADER(X-ENVOY-ORIGINAL-PATH?:PATH)%"
84+
protocol: "%PROTOCOL%"
85+
response_code: "%RESPONSE_CODE%"
86+
response_flags: "%RESPONSE_FLAGS%"
87+
bytes_received: "%BYTES_RECEIVED%"
88+
bytes_sent: "%BYTES_SENT%"
89+
duration: "%DURATION%"
90+
authority: "%REQUEST_HEADER(:AUTHORITY)%"
91+
upstream_host: "%UPSTREAM_HOST%"
92+
93+
Update the ``GatewayClass`` to reference the ``CiliumGatewayClassConfig`` resource:
94+
95+
.. code-block:: yaml
96+
97+
apiVersion: gateway.networking.k8s.io/v1
98+
kind: GatewayClass
99+
metadata:
100+
name: cilium
101+
spec:
102+
controllerName: io.cilium/gateway-controller
103+
parametersRef:
104+
group: cilium.io
105+
kind: CiliumGatewayClassConfig
106+
name: cilium
107+
namespace: default
108+
109+
Verify that the GatewayClass configuration is accepted:
110+
111+
.. code-block:: shell-session
112+
113+
$ kubectl get ciliumgatewayclassconfig cilium
114+
NAME ACCEPTED AGE
115+
cilium True 33s
116+
117+
Send a request through the Gateway:
118+
119+
.. code-block:: shell-session
120+
121+
$ GATEWAY=$(kubectl get gateway my-gateway -o jsonpath='{.status.addresses[0].value}')
122+
$ curl --fail -s http://"$GATEWAY"/details/1 | jq
123+
124+
Verify access logs
125+
==================
126+
127+
Check the Envoy stdout logs for an access log entry that contains the Gateway
128+
namespace and name.
129+
130+
.. code-block:: shell-session
131+
132+
$ kubectl -n kube-system logs -l app.kubernetes.io/name=cilium-envoy,app.kubernetes.io/part-of=cilium | grep default/my-gateway
133+
{"authority":"172.18.255.193","bytes_received":0,"bytes_sent":178,"duration":8,"gateway":"default/my-gateway","method":"GET","path":"/details/1","protocol":"HTTP/1.1","response_code":200,"response_flags":"-","start_time":"2026-07-06T10:10:13.622Z","upstream_host":"10.244.0.221:9080"}
134+
135+
Log HTTP and TCP traffic
136+
========================
137+
138+
To emit access logs for both HTTP and TCP proxy traffic, set both targets:
139+
140+
.. code-block:: yaml
141+
142+
spec:
143+
telemetry:
144+
accessLogs:
145+
- format: Text
146+
text: '[%START_TIME%] %CILIUM_GATEWAY_NAMESPACE%/%CILIUM_GATEWAY_NAME% "%REQUEST_HEADER(:METHOD)% %REQUEST_HEADER(X-ENVOY-ORIGINAL-PATH?:PATH)% %PROTOCOL%" %RESPONSE_CODE% %DURATION%'
147+
targets:
148+
- HTTP
149+
- TCP
150+
151+
Multiple access log entries may use the same target. Envoy emits one log entry
152+
for each matching configuration, so duplicate configurations will produce
153+
duplicate log lines.
154+
155+
__ https://www.envoyproxy.io/docs/envoy/latest/configuration/observability/access_log/usage
156+
__ https://www.envoyproxy.io/docs/envoy/latest/configuration/observability/access_log/usage#default-format-string
157+
__ https://www.envoyproxy.io/docs/envoy/latest/configuration/advanced/substitution_formatter

Documentation/network/servicemesh/gateway-api/gateway-api.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Cilium's Gateway API features:
7272
parameterized-gatewayclass
7373
default-tls-certificate
7474
backendtlspolicy
75+
access-logs
7576

7677
More examples can be found in the `upstream repository <https://github.com/kubernetes-sigs/gateway-api/tree/v1.3.0/examples/standard>`_.
7778

Documentation/spelling_wordlist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ fieldAggregate
377377
filesystem
378378
filesystems
379379
firewalling
380+
formatters
380381
fortio
381382
fqdn
382383
fromCIDR

0 commit comments

Comments
 (0)