Assumption is that you have Strimzi already running as my-cluster-kafka
on the kafka
namespace.
Create a deployment with a recent kafkacat
, like:
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
run: kafkacat
name: kafkacat
spec:
replicas: 1
selector:
matchLabels:
run: kafkacat
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
run: kafkacat
spec:
containers:
- image: confluentinc/cp-kafkacat
name: kafkacat
resources: {}
command:
- sh
- -c
- "exec tail -f /dev/null"
status: {}
Now k apply -f
that file, and once the pod is ready, open a bash
session, like:
k exec -it kafkacat-xxxxx-yyyyy -- bash
On the pod you now run something like the following to see all data, including record headers on a given topic:
kafkacat -C -b my-cluster-kafka-bootstrap.kafka.svc.cluster.local:9092 -t knative-messaging-kafka.default.testchannel \
-f '\nKey (%K bytes): %k
Value (%S bytes): %s
Timestamp: %T
Partition: %p
Offset: %o
Headers: %h\n'
This launches kafkacat
as a consumer (-C
) against the Strimzi broker (-b
) with a given topic (-t
), where all records on the topic are rendered, including its headers.
This might give you a message like:
...
Key (-1 bytes):
Value (1111 bytes): {"apiVersion":"v1","count":1,"eventTime":null,"firstTimestamp":"2021-05-19T07:01:04Z","involvedObject":{"apiVersion":"v1","fieldPath":"spec.containers{curlcli}","kind":"Pod","name":"curlcli","namespace":"default","resourceVersion":"272474","uid":"f0e510fa-2740-4a2e-8eb5-da02826e4fae"},"kind":"Event","lastTimestamp":"2021-05-19T07:01:04Z","message":"Created container curlcli","metadata":{"creationTimestamp":"2021-05-19T07:01:04Z","managedFields":[{"apiVersion":"v1","fieldsType":"FieldsV1","fieldsV1":{"f:count":{},"f:firstTimestamp":{},"f:involvedObject":{"f:apiVersion":{},"f:fieldPath":{},"f:kind":{},"f:name":{},"f:namespace":{},"f:resourceVersion":{},"f:uid":{}},"f:lastTimestamp":{},"f:message":{},"f:reason":{},"f:source":{"f:component":{},"f:host":{}},"f:type":{}},"manager":"kubelet","operation":"Update","time":"2021-05-19T07:01:04Z"}],"name":"curlcli.168065ae11d6cbd2","namespace":"default","resourceVersion":"272480","uid":"c390edf8-7146-4b2c-a990-bf9385e055be"},"reason":"Created","reportingComponent":"","reportingInstance":"","source":{"component":"kubelet","host":"minikube"},"type":"Normal"}
Timestamp: 1621407664155
Partition: 1
Offset: 82
Headers: ce_time=2021-05-19T07:01:04.155157925Z,ce_id=1daca56a-d50c-472d-b9c8-e9e77435e280,ce_subject=/apis/v1/namespaces/default/events/curlcli.168065ae11d6cbd2,ce_name=curlcli.168065ae11d6cbd2,ce_specversion=1.0,ce_kind=Event,ce_namespace=default,ce_source=https://10.96.0.1:443,ce_type=dev.knative.apiserver.resource.add,content-type=application/json,traceparent=00-c1df3d88293179613b385eb838115c41-d2a3441d93e0f4d1-00
% Reached end of topic knative-messaging-kafka.default.testchannel [1] at offset 83
...