<p>I am building my docker image with jenkins using:</p>

<pre><code>docker build --build-arg VCS_REF=$GIT_COMMIT \
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
--build-arg BUILD_NUMBER=$BUILD_NUMBER -t $IMAGE_NAME\ 
</code></pre>

<p>I was using Docker but I am migrating to k8.</p>

<p>With docker I could access those labels via:</p>

<pre><code>docker inspect --format "{{ index .Config.Labels \"$label\"}}" $container
</code></pre>

<p><b>How can I access those labels with Kubernetes ?</b></p>

<p>I am aware about adding those labels in .Metadata.labels of my yaml files but I don't like it that much because 
- it links those information to the deployment and not the container itself<BR> 
- can be modified anytime<BR> 
...</p>

<pre><code>kubectl describe pods
</code></pre>

<p>Thank you</p>

sam
<p>Kubernetes doesn't expose that data.  If it did, it would be part of the <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#podstatus-v1-core" rel="nofollow noreferrer">PodStatus</a> API object (and its embedded <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#containerstatus-v1-core" rel="nofollow noreferrer">ContainerStatus</a>), which is one part of the <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#pod-v1-core" rel="nofollow noreferrer">Pod</a> data that would get dumped out by <code>kubectl get pod deployment-name-12345-abcde -o yaml</code>.</p>

<p>You might consider encoding some of that data in the Docker image tag; for instance, if the CI system is building a tagged commit then use the source control tag name as the image tag, otherwise use a commit hash or sequence number.  Another typical path is to use a deployment manager like <a href="https://helm.sh" rel="nofollow noreferrer">Helm</a> as the principal source of truth about deployments, and if you do that there can be a path from your CD system to Helm to Kubernetes that can pass along labels or annotations.  You can also often set up software to know its own build date and source control commit ID at build time, and then expose that information via an informational-only API (like an HTTP <code>GET /_version</code> call or some such).</p>
