【问题标题】:how to set image name/tag for container images specified in CRDs in kustomization.yaml如何为 kustomization.yaml 中的 CRD 中指定的容器镜像设置镜像名称/标签
【发布时间】:2021-07-07 14:47:43
【问题描述】:

如何使用 images 字段通过kustomization.yaml 为 CRD 中指定的容器图像设置图像名称/标签?

images 字段在 DeploymentStatefulSet 中指定容器图像时效果很好,但不能从以下位置转换 CRD 资源:

apiVersion: foo.example.com/v1alpha1
kind: Application
spec:
  image: xxx

收件人:

apiVersion: foo.example.com/v1alpha1
kind: Application
spec:
  image: new-image:tag

【问题讨论】:

标签: kubernetes kustomize


【解决方案1】:

您的任务可以使用yq 轻松解决。该命令取决于您使用的yq 实现:

mikefarah/yq - version 4

IMAGE="new-image:tag" yq e '.spec.image = strenv(IMAGE)'

kislyuk/yq

yq -y --arg IMAGE "new-image:tag" '.spec.image |= $IMAGE'

【讨论】:

  • 谢谢!我相信它可以通过使用yq 来工作。包含像 kustomize 插件这样的解决方案会很棒,这样它就可以用 YAML 完成
【解决方案2】:

这是一个使用ImageTagTransformer 的工作示例。

给出以下 yaml 文件:

# transformer_1.yaml
---
apiVersion: builtin
kind: ImageTagTransformer
metadata:
  name: not-important-here
imageTag:
  name: xxx
  newName: new-image
  newTag: tag
fieldSpecs:
- path: spec/image
  kind: Application

# application.yaml
---
apiVersion: foo.example.com/v1alpha1
kind: Application
spec:
  image: xxx

# kustomization.yaml
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- application.yaml
transformers:
- transformer_1.yaml

运行这个命令:

$ kustomize build ./ | kpt cfg grep "kind=Application"
apiVersion: foo.example.com/v1alpha1
kind: Application
spec:
  image: new-image:tag

但是,我仍然需要想办法让它与 skaffold 工作流程一起工作。

更新

skaffold 社区的feedback 表示它不支持重写清单,除非那些在allowlist 中。所以吸取的教训是,skaffold 还不支持重写任何 CRD。

【讨论】:

    猜你喜欢
    • 2016-12-23
    • 1970-01-01
    • 1970-01-01
    • 2020-03-11
    • 2020-05-01
    • 1970-01-01
    • 2020-04-29
    • 2017-10-03
    • 1970-01-01
    相关资源
    最近更新 更多