Shresthi Garg
Shresthi Garg

Reputation: 25

Getting Pod and Node's events millisecond level precision in a kubernetes cluster

I have a Kubernetes cluster and I need to collect the various pod and node event timestamps.

I do that by building a go service that communicates with my Kubernetes cluster via client-go library. The timestamp I get for the subscribed pod and node object shows time only till seconds precision.

Is there a way one can get time in milliseconds precision level? I found a similar issue raised but there is no resolution of that.

Could someone help me in this?

Upvotes: 2

Views: 1484

Answers (1)

moonkotte
moonkotte

Reputation: 4181

Welcome to the community @shresthi-garg

First of all, as you correctly found, it's not possible to get precise timestamps from kubernetes components themselves with milliseconds precision. And this github issue is closed for now.

However it's still possible to find some exact timings about containers and other events. Below is an example related to a container.

Option 1 - kubelet by default writes significant amount of logs to syslog. It's possible to view them with using journalctl (note! this approach works on systemd systems. For other systems please refer to official kubenetes documentation). Example of the command:

journalctl -u kubelet -o short-precise

-u - filter by unit

-o - output options

Line from output which we're looking for will be:

May 18 21:00:30.221950 control-plane kubelet[8576]: I0518 21:00:30.221566    8576 scope.go:111] "RemoveContainer" containerID="d7d0403807684ddd4d2597d32b90b1e27d31f082d22cededde26f6da8281cd92"

Option 2 - get this information from containerisation engine. In the example below I used Docker for this. I run this command:

docker inspect container_id/container_name

Output will be like:

{
        "Id": "d7d0403807684ddd4d2597d32b90b1e27d31f082d22cededde26f6da8281cd92",
        "Created": "2021-05-18T21:00:07.388569335Z",
        "Path": "/docker-entrypoint.sh",
        "Args": [
            "nginx",
            "-g",
            "daemon off;"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 8478,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2021-05-18T21:00:07.593216613Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        }

Upvotes: 2

Related Questions