如果您使用Kustomize来管理Rollout
使用kustomize管理Rollout的manifest文件时,与Deployment情况不同的地方有些让人困惑,因此在这里记下了一些笔记。
准备工作
以下是構成。
.
├── base
│ └── nginx
│ ├── kustomization.yaml
│ └── nginx.yaml
└── overlay
├── dev
│ └── kustomization.yaml
└── prod
└── kustomization.yaml
基于的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
问题
使用以下命令构建以下kustomize.yaml:kustomize build overlay/dev,并设置resource值。
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/
构建结果如下,令人惊讶的是,所有基础内容都被覆盖了。
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
解决方法 (jiě jué àn)
如果您在Kustomize中管理Rollout的清单,可以在以下进行记录。
根据上述,需要以下文件。
-
- rollout-transform.yaml
- rollout_cr_schema.json
将上述文件按照以下方式进行布置。
.
├── 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
自定义化.yaml
将kustomize.yaml文件按照以下方式进行修改,并将该文件在openapi配置中指定。
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
如果使用以下命令进行构建,将生成以下清单:
正如期望的那样,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