Kubernetes中的容器标签 [英] container labels in kubernetes

查看:100
本文介绍了Kubernetes中的容器标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jenkins构建我的docker映像,

I am building my docker image with jenkins using:

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\ 

我使用的是Docker,但我正在迁移到k8.

I was using Docker but I am migrating to k8.

使用docker,我可以通过以下方式访问这些标签:

With docker I could access those labels via:

docker inspect --format "{{ index .Config.Labels \"$label\"}}" $container

如何使用Kubernetes访问这些标签?

我知道要在yaml文件的.Metadata.labels中添加这些标签,但是我不太喜欢,因为 -它将那些信息链接到部署而不是容器本身
-可以随时修改
...

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
- can be modified anytime
...

kubectl describe pods

谢谢

推荐答案

Kubernetes不会公开该数据.如果确实如此,它将成为 PodStatus API对象(及其嵌入的 Pod 数据会被kubectl get pod deployment-name-12345-abcde -o yaml丢弃.

Kubernetes doesn't expose that data. If it did, it would be part of the PodStatus API object (and its embedded ContainerStatus), which is one part of the Pod data that would get dumped out by kubectl get pod deployment-name-12345-abcde -o yaml.

您可能会考虑在Docker image标签中对其中的一些数据进行编码;例如,如果CI系统正在构建带标记的提交,则使用源控制标签名称作为图像标签,否则使用提交哈希或序列号.另一个典型的途径是使用诸如 Helm 之类的部署管理器作为有关部署的主要事实来源,如果您这样做的话,可以是从CD系统到Helm到Kubernetes的路径,可以传递标签或注释.您通常还可以设置软件以在构建时知道其自身的构建日期和源代码控制提交ID,然后通过仅提供信息的API(例如HTTP GET /_version调用或类似的方法)公开该信息.

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 Helm 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 GET /_version call or some such).

这篇关于Kubernetes中的容器标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆