Skip to main content

kustomize

caution
  • 不支持移除资源 - #1593
# macOSbrew install kustomize

目录结构#

# 应用基础目录mkdir -p app/base app/overlays/{staging,production}
# kustomize build 生成 yaml# 部署不同环境kustomize build ~/ldap/overlays/staging | kubectl apply -f - --context stagingkustomize build ~/ldap/overlays/production | kubectl apply -f - --context production
# -k 可直接 applykubectl apply -k ~/ldap/overlays/staging --context stagingkubectl apply -k ~/ldap/overlays/production --context production
~/someApp - 基础应用目录├── base - 基础层│   ├── deployment.yaml│   ├── kustomization.yaml│   └── service.yaml└── overlays - 叠加层    ├── development - base+开发环境自定义内容    │   ├── cpu_count.yaml    │   ├── kustomization.yaml    │   └── replica_count.yaml    └── production - base+生产环境自定义内容        ├── cpu_count.yaml        ├── kustomization.yaml        └── replica_count.yaml

示例#

批量合并修改#

kustomization.yaml

patches:  - target:      kind: Application    path: patch.yaml

patch.yaml

apiVersion: argoproj.io/v1alpha1kind: Applicationmetadata:  # 匹配所有  name: '*'spec:  project: dev-cluster

FAQ

accumulating resources: accumulation err='merging resources from 'res.yaml': may not add resource with an already registered id#

检查是否已经定义过资源

index out of range [4] with length 4#

YAML 语法可能没有问题,但是有 CJK 可能会导致这个异常