Is it possible for a container running in kubernetes to access its container id? If I have a service (my term, not kubernetes) and have scaled it 5 times horizontally, I want to log to stdout including the individual container id. Is this possible, or indeed is this even something I should be doing? I may not have grasped the concepts behind kubernetes services yet.
Have you try the downward API volume? It's one easy way to put Pod and container metadata inside your container. Although it doesn't mention the container id, other metadata might be useful.
https://kubernetes.io/docs/tasks/inject-data-application/downward-api-volume-expose-pod-information/
Another option is to include kubectl
in your container as explained in this answer
For OpenShift, and therefore I presume also Kubernetes, you can possibly look up the HOSTNAME
environment variable and use the value of it. This will be the name of the pod. I know it isn't the container ID, but could be close enough.