【问题标题】:yaml anchor a list object, and merge with kustomizeyaml 锚定一个列表对象,并与 kustomize 合并
【发布时间】:2021-10-25 23:50:01
【问题描述】:

我有兴趣将 YAML 锚点用于对象列表。我有一个 Kubernetes pod 清单,其中包含一个容器列表。我正在尝试使用 kustomize 构建它,但我找不到正确的语法。

所以,我认为这看起来最正确。

apiVersion: v1
kind: Pod
metadata: { name: anchor-test }
spec:
  containers:
  - &foo
    name: foo
    image: traefik/whoami
    ports: [ containerPort: 80 ]
  - <<: *foo
    name: bar

但是 kustomize 抛出这个错误:

Error: map[string]interface {}{"apiVersion":"v1", "kind":"Pod", "metadata":map[string]interface {}{"name":"anchor-test"}, "spec":map[string]interface {}{"containers":[]interface {}{map[string]interface {}{"image":"traefik/whoami", "name":"foo", "ports":[]interface {}{map[string]interface {}{"containerPort":80}}}, map[interface {}]interface {}{"image":"traefik/whoami", "name":"bar", "ports":[]interface {}{map[string]interface {}{"containerPort":80}}}}}}: 
json: unsupported type: map[interface {}]interface {}

【问题讨论】:

    标签: kubernetes yaml kustomize


    【解决方案1】:

    所以,这个问题是kustomize 特有的。它适用于kubectl apply -f。这意味着 YAML 实际上是这样有效的。可以用http://www.yamllint.com/进行测试。

    所以目前,kustomize 无法做到这一点。 GitHub 上有一些关于此的问题。

    【讨论】:

    • FWIW:看起来这个问题刚刚在 Kustomize 4.4.0 及更高版本的第二个问题 (#3675) 中得到修复(还不能测试它)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-21
    • 2017-03-23
    • 1970-01-01
    • 1970-01-01
    • 2021-01-21
    • 1970-01-01
    • 2015-09-04
    相关资源
    最近更新 更多