Rolloutのmanifestファイルをkustomizeで管理する際、Deploymentの場合と異なる部分があり、少しはまったのでメモしておきます。
Preparations
構成は以下です。
.
├── base
│ └── nginx
│ ├── kustomization.yaml
│ └── nginx.yaml
└── overlay
├── dev
│ └── kustomization.yaml
└── prod
└── kustomization.yaml
baseとなるnginx.yamlは以下
---
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: nginx
labels:
app: nginx
spec:
replicas: 1
revisionHistoryLimit: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
env:
- name: MSG1
value: 'msg1'
- name: MSG2
value: 'msg2'
ports:
- containerPort: 80
strategy:
blueGreen:
autoPromotionEnabled: true
activeService: nginx
---
apiVersion: v1
kind: Service
metadata:
name: nginx
spec:
ports:
- name: http
protocol: "TCP"
port: 80
targetPort: 80
selector:
app: nginx
Problem
以下のkustomize.yamlを以下のコマンドでbuildします。(resource値を設定)
kustomize build overlay/dev
resources:
- ../../base/nginx
images:
- name: nginx
newTag: '1.23'
patchesStrategicMerge:
- |-
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: nginx
spec:
template:
spec:
containers:
- name: nginx
resources:
requests:
memory: 1500M
cpu: 1000m
limits:
memory: 1500M
cpu: 1000m
*kustomize.yamlに記載されているそのほかの設定値については以下にドキュメントがありますので説明は割愛します。
https://kubectl.docs.kubernetes.io/references/kustomize/kustomization/
build結果は以下になり、なんとbaseの内容がすべて上書きされてしまいます。
apiVersion: v1
kind: Service
metadata:
name: nginx
spec:
ports:
- name: http
port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx
---
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
labels:
app: nginx
name: nginx
spec:
replicas: 1
revisionHistoryLimit: 3
selector:
matchLabels:
app: nginx
strategy:
blueGreen:
activeService: nginx
autoPromotionEnabled: true
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
# resources以外の値が上書きされてしまいます
resources:
limits:
cpu: 1000m
memory: 1500M
requests:
cpu: 1000m
memory: 1500M
Solution
kustomizeでRolloutのmanifestを管理する場合については以下に記載がありました。
上記によると、以下のファイルが必要とのこと
上記ファイルを以下の様に配置します。
.
├── base
│ └── nginx
│ ├── kustomization.yaml
│ └── nginx.yaml
└── overlay
├── dev
│ ├── kustomization.yaml
│ ├── rollout_cr_schema.json
│ └── rollout-transform.yaml
└── prod
├── kustomization.yaml
├── rollout_cr_schema.json
└── rollout-transform.yaml
kustomize.yaml
kustomize.yamlを以下の様に修正し、上記ファイルはopenapi
configurations
で指定します。
resources:
- ../../base/nginx
openapi:
# curl -OL https://github.com/argoproj/argo-rollouts/raw/master/docs/features/kustomize/rollout_cr_schema.json
path: rollout_cr_schema.json
configurations:
# curl -OL https://argoproj.github.io/argo-rollouts/features/kustomize/rollout-transform.yaml
- rollout-transform.yaml
images:
- name: nginx
newTag: '1.23'
patchesStrategicMerge:
- |-
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: nginx
spec:
template:
spec:
containers:
- name: nginx
resources:
requests:
memory: 1500M
cpu: 1000m
limits:
memory: 1500M
cpu: 1000m
configurations
については以下の様に記載できるらしいですが、
パスが変わったりファイルの内容が変わり非互換とかあったらいやだなと思い事前にダウンロードして配置しました。
(以下の記載のほうが一般的なのだろうか。)
configurations:
- https://argoproj.github.io/argo-rollouts/features/kustomize/rollout-transform.yaml
再度以下のコマンドでbuildすると、以下の様に、manifestが生成されます。
期待通り、resourcesの値がbaseに追加されてます。
kustomize build overlay/dev
apiVersion: v1
kind: Service
metadata:
name: nginx
spec:
ports:
- name: http
port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx
---
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
labels:
app: nginx
name: nginx
spec:
replicas: 1
revisionHistoryLimit: 3
selector:
matchLabels:
app: nginx
strategy:
blueGreen:
activeService: nginx
autoPromotionEnabled: true
template:
metadata:
labels:
app: nginx
spec:
containers:
- env:
- name: MSG1
value: msg1
- name: MSG2
value: msg2
image: nginx:1.23
name: nginx
ports:
- containerPort: 80
resources: # <- 追加されている
limits:
cpu: 1000m
memory: 1500M
requests:
cpu: 1000m
memory: 1500M