Home > database >  How to pass a flag to klog for structured logging
How to pass a flag to klog for structured logging

Time:11-18

As part of kubernetes 1.19, structured logging has been implemented.

I've read that kubernetes log's engine is klog and structured logs are following this format :

<klog header> "<message>" <key1>="<value1>" <key2>="<value2>" ...

Cool ! But even better, you apparently can pass a --logging-format=json flag to klog so logs are generated in json directly !

{
   "ts": 1580306777.04728,
   "v": 4,
   "msg": "Pod status updated",
   "pod":{
      "name": "nginx-1",
      "namespace": "default"
   },
   "status": "ready"
}

Unfortunately, I haven't been able to find out how and where I should specify that --logging-format=json flag.

Is it a kubectl command? I'm using Azure's aks.

CodePudding user response:

--logging-format=json is a flag which need to be set on all Kuberentes System Components ( Kubelet, API-Server, Controller-Manager & Scheduler). You can check all flags here.

Unfortunately you cant do it right now with AKS as you have the managed control plane from Microsoft.

  • Related