【问题标题】:Adding time stamp to Kubernetes deployment with latest tag使用最新标签向 Kubernetes 部署添加时间戳
【发布时间】:2019-10-25 15:06:53
【问题描述】:

我正在尝试实现 Kubernetes 资源部署。为此,我创建了 deployment.yamlservice.yaml 作为我的 Kubernetes 资源。并在我的deployment.yaml. When I am doing like this, latest image is not pulling withlatest`标签中引用带有latest标签的dockerhub注册表图像。

所以我在部署中添加了时间戳,如下所示:

template:
 metadata:
  labels:
    app: test-kube-deployment
    date: date "+%H:%M:%S   %d/%m/%y"
spec:
  imagePullSecrets:
    - name: "regcred"
  containers:
   - name: test-kube-deployment-container
     image: spacestudymilletech010/spacestudykubernetes:latest
     imagePullPolicy: Always
     ports:
        - name: http
          containerPort: 8085
          protocol: TCP

当我在这里添加时间时,我收到如下错误,

The Deployment "test-kube-deployment" is invalid: spec.template.labels: Invalid value: "date \"+%H:%M:%S   %d/%m/%y\"": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character 

我需要做哪些修改来定义我的时间戳以唯一标识我的 Docker 映像?

【问题讨论】:

  • 不要将其添加为标签,而是添加为注释。 ``` 模板:元数据:标签:应用程序:test-kube-deployment 注释:日期:“+%H:%M:%S %d/%m/%y”日期:日期“+%H:%M: %S %d/%m/%y" ```
  • 最好还是让它成为图像的标签,例如.../spacestudykubernetes:20191025.2302。如果此图像由于某种原因无法正常工作,那么恢复到以前的图像非常简单。

标签: kubernetes yaml


【解决方案1】:

不要将其添加为标签,而是添加为注释。

template: 
  metadata: 
    labels: 
      app: test-kube-deployment 
    annotations: 
      date: "+%H:%M:%S %d/%m/%y"

PD.- 您收到错误是因为标签不接受 +、% 和 : 字符。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-24
    • 1970-01-01
    • 2019-12-10
    相关资源
    最近更新 更多