kuberneteskubelet

How to enable k8s to log label data in the log


Is there a way to let docker/kubelet to log the labels of a pod in the log? What is the configuration?

For now, we can only get the labels of a running pod, if a pod is gone, you cannot use kubectl/docker describe to get the metadata of a pod.

I am trying to get the metadata especially the labels of a pod that already diminished


Solution

  • I think that I found the answer by myself.

    There is no direct way to log the metadata for a pod in the log. Based on the documents in K8s, there are 2 ways

    1. Expose the metadata using environment variables and print the env out. See this document
    2. Expose the metadata using dowanward volume api. You can expose the metadata to a volume and then read it from there. See this document