The timestamp at which the docker container was created can be known using:
docker inspect --format='{{.Created}}' 6de2e88f7859
2020-12-08T17:29:37.769047437Z
Similarly, the timestamp at which the kubernetes pod (to which this container belongs) was created can be known using:
kubectl describe pod <pod-name>
Name: <pod-name>
Namespace: default
Priority: 0
Node: xyz.com/11.11.11.11
Start Time: Tue, 08 Dec 2020 17:29:36 +0000
I want to add this pod/container creation timestamp (preferably pod creation timestamp - mentioned as Start Time: Tue, 08 Dec 2020 17:29:36 +0000
in the kubectl describe pod <pod-name>
output) as one of the container labels available (.Config.Labels). Some default labels are:
io.kubernetes.container.name, io.kubernetes.pod.name, annotation.io.kubernetes.container.hash, annotation.io.kubernetes.container.ports, etc. These labels can be seen using the following command:
docker inspect --format='{{json .Config.Labels}}' <container-id>
However, I couldn't find the pod/container creation time label here. Is there any way to add this pod/container creation timestamp as one of the labels?
I'm looking for a container label here as I want to add that to /etc/docker/daemon.json
file.
Look at the code: kubelet/kuberuntime/labels.go
It doesn't look like you can dynamically add new labels.
Already existing labels are "hardcoded" and if you want to add some new ones, you would need to add them in code, compile it and swap the kubelet binaries.