Ở bài trước chúng ta mới dùng chart của người khác. Bài này mình sẽ cùng mọi người tự viết Helm chart cho TaskFlow: template, values, helper, ghép DATABASE_URL từ một mật khẩu (việc Kustomize ở Bài 22 chưa làm được), migration bằng hook, helm lint, helm test, đóng gói, rồi chốt dùng Kustomize hay Helm. Chart được cài vào namespace taskflow-helm với hostname helm.taskflow.local, stack Kustomize trong taskflow chạy song song và không bị đụng tới.
1. Khung chart từ helm create.
helm create taskflow
# Creating taskflow
Khung này là một web server nginx mẫu. Mình giữ Chart.yaml, .helmignore (file bỏ qua khi đóng gói), NOTES.txt, tests/, viết lại _helpers.tpl; xóa hpa.yaml (Bài 25), ingress.yaml (series dùng Gateway API), serviceaccount.yaml (Bài 27); phần còn lại thay bằng manifest của kustomize/base chuyển thành template (api.yaml là Deployment + Service taskflow-api, tương tự notifier.yaml, postgres.yaml, redis.yaml..., thêm secret.yaml, migrate-job.yaml, tests/test-ready.yaml).
PostgreSQL và Redis là bản tự viết của Bài 19, nằm trong chart để một lệnh helm install ra TaskFlow chạy đủ, tắt được bằng postgresql.enabled, redis.enabled khi đã có database riêng; Gateway cũng tắt được (gateway.enabled: false) để gắn HTTPRoute vào Gateway có sẵn (gateway.existingGateway, thêm existingGatewayNamespace nếu nó ở namespace khác); khi đó listener của Gateway kia phải nhận route từ namespace của release (allowedRoutes.namespaces.from: All hoặc Selector), Gateway của series để Same nên không nhận. Namespace, ResourceQuota, LimitRange thuộc về namespace chứ không thuộc ứng dụng nên không có trong chart; CronJob backup để lại cho Kustomize.
apiVersion: v2
name: taskflow
description: TaskFlow API trên Kubernetes (series Học Kubernetes, toidicode.com)
type: application
# version của chart: tăng mỗi khi template hoặc values mặc định đổi
version: 0.1.0
# version của TaskFlow, là tag image mặc định
appVersion: "0.53.0"
2. values.yaml và template.
values.yaml là "giao diện" của chart, mặc định hợp với cụm kind:
- charts/taskflow/values.yaml (một phần)
image:
repository: taskflow-api
# để trống: dùng appVersion trong Chart.yaml
tag: ""
pullPolicy: IfNotPresent
api:
replicas: 3
# ... resources như Bài 16; notifier.resources
# ConfigMap của taskflow-api, mỗi key một biến môi trường (Bài 13).
# TASKFLOW_NOTIFIER_ADDR do chart tự điền theo tên Service của notifier.
config:
TASKFLOW_LOG_FORMAT: json
TASKFLOW_LOG_LEVEL: info
# ... SHUTDOWN_DELAY, WORKERS, CORS_ORIGIN, TRUSTED_PROXIES như overlay dev
# ... auth (phần 4), gateway, uploads, postgresql, redis, migration
Template là manifest có chèn Go template (cú pháp text/template như bài html/template của series Golang) cộng các hàm của thư viện Sprig:
- charts/taskflow/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "taskflow.fullname" . }}-config
labels:
{{- include "taskflow.labels" (dict "root" $ "component" "config") | nindent 4 }}
data:
{{- range $key, $value := .Values.config }}
{{ $key }}: {{ $value | quote }}
{{- end }}
# api gọi notifier qua Service của chart (Bài 21)
TASKFLOW_NOTIFIER_ADDR: {{ include "taskflow.fullname" . }}-notifier:9090
Trong đó:
.Valueslà values đã trộnvalues.yaml,-f,--set;.ReleasecóName,Namespace,Service(luôn làHelm);.ChartlàChart.yaml;$trỏ về gốc, cần khi ở trongrange.{{-,-}}xóa khoảng trắng, xuống dòng phía trước, phía sau. Thụt dòng sai là lỗi hay gặp nhất, luôn xem kết quả bằnghelm template.quoteđặt giá trị trong nháy vì data của ConfigMap chỉ nhận chuỗi (lỗi số không nháy ở Bài 13 không còn).includegọi template đặt tên trong_helpers.tpl, trả về chuỗi;nindent 4xuống dòng rồi thụt 4 dấu cách từng dòng.
templates/api.yaml là Deployment, Service của kustomize/base, giá trị theo môi trường lấy từ values:
- charts/taskflow/templates/api.yaml (một phần)
app.kubernetes.io/version: {{ include "taskflow.tag" . | quote }}
annotations:
# hash của ConfigMap: đổi config là đổi Pod template, Deployment tự rollout
checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
# ...
image: "{{ .Values.image.repository }}:{{ include "taskflow.tag" . }}"
# ...
resources:
{{- toYaml .Values.api.resources | nindent 12 }}
Helper taskflow.tag trả image.tag, trống thì lấy appVersion; image và label version cùng dùng nó nên version chỉ ở một chỗ, không cần replacements như Kustomize. ConfigMap giữ tên cố định, nên thay cho hash suffix, annotation checksum/config băm SHA-256 template ConfigMap: config đổi thì Pod template đổi, Deployment tự rolling update. Nhưng ConfigMap cũ không còn, kubectl rollout undo lùi Pod mà vẫn đọc config mới; lùi cả hai thì dùng helm rollback.
3. _helpers.tpl: tên, label và selector.
- charts/taskflow/templates/_helpers.tpl (một phần)
{{/*
Label chọn Pod, dùng trong selector của Deployment, StatefulSet, Service.
Selector không sửa được sau khi tạo (Bài 9): KHÔNG thêm version hay chart vào đây.
Tham số: dict "root" $ "component" "api" (tùy chọn "name", mặc định <fullname>-<component>)
*/}}
{{- define "taskflow.selectorLabels" -}}
app.kubernetes.io/name: {{ .name | default (printf "%s-%s" (include "taskflow.fullname" .root) .component) }}
app.kubernetes.io/component: {{ .component }}
app.kubernetes.io/instance: {{ .root.Release.Name }}
{{- end }}
{{/*
Label đầy đủ cho metadata.labels của mọi resource (quy ước Bài 7 + label của Helm).
*/}}
{{- define "taskflow.labels" -}}
{{ include "taskflow.selectorLabels" . }}
app.kubernetes.io/part-of: taskflow
app.kubernetes.io/managed-by: {{ .root.Release.Service }}
helm.sh/chart: {{ printf "%s-%s" .root.Chart.Name .root.Chart.Version }}
{{- end }}
Trong đó:
taskflow.fullname(bản rút gọn củahelm create, không in ở đây) lấy tên release làm tiền tố, cắt ở 63 ký tự: releasetaskflowcho ra đúngtaskflow-api,taskflow-notifier,taskflow-postgres,taskflow-redis; releasedemothànhdemo-taskflow-api..., hai release cùng namespace không đụng nhau.- Template chỉ nhận một tham số, nhiều thứ thì gói vào
dict. Label giữ quy ước Bài 7 (nametrùng tên resource,componentapi,database,cache...). - Selector chỉ thêm
instanceđể hai release không chọn nhầm Pod của nhau. Selector của Deployment không sửa được (field is immutable, Bài 22), cònhelm.sh/chartđổi theo version chart,versionđổi theo image, nên hai label này chỉ nằm tronglabels(label khuyến nghị của Helm).managed-byvàinstancelà hai label Bài 7 hẹn để Helm đặt.
4. Mật khẩu và Job migration.
Một mật khẩu cho cả database lẫn URL
TaskFlow đọc chuỗi kết nối, PostgreSQL và Redis đọc mật khẩu trần. Chart chỉ lưu mật khẩu, URL ghép trong helper dùng chung cho taskflow-api và Job migration:
- charts/taskflow/templates/_helpers.tpl (tiếp)
{{- define "taskflow.connectionEnv" -}}
{{- $fullname := include "taskflow.fullname" . }}
{{- $pgHost := .Values.postgresql.host | default (printf "%s-postgres" $fullname) }}
{{- $redisHost := .Values.redis.host | default (printf "%s-redis" $fullname) -}}
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: {{ include "taskflow.secretName" . }}
key: postgres-password
- name: DATABASE_URL
value: {{ printf "postgres://%s:$(POSTGRES_PASSWORD)@%s:5432/%s?sslmode=disable" (urlquery .Values.postgresql.user) $pgHost (urlquery .Values.postgresql.database) | quote }}
# ... REDIS_PASSWORD và TASKFLOW_REDIS_URL "redis://:$(REDIS_PASSWORD)@<host>:6379/0"
{{- end }}
printf ghép phần chart biết (user, host, database; urlquery mã hóa ký tự đặc biệt nếu có), còn $(POSTGRES_PASSWORD) do kubelet thay bằng biến khai báo ngay phía trên khi tạo container. Helm không cần đọc mật khẩu, nên Secret có thể do người khác tạo và mật khẩu không vào release Secret của Helm (Bài 23). Đổi lại kubelet chép nguyên văn, không mã hóa URL, nên mật khẩu chỉ được gồm chữ và số.
Secret: tạo sẵn hoặc để chart sinh
Helper taskflow.secretName trả auth.existingSecret nếu có, không thì <fullname>-auth. Nên tạo Secret trước, ngoài git, rồi chỉ ghi tên vào values (bỏ --dry-run=client là tạo thật):
kubectl create secret generic taskflow-auth-that -n taskflow-helm --from-literal=postgres-password=$(openssl rand -hex 24) --from-literal=redis-password=$(openssl rand -hex 24) --from-literal=jwt-secret=$(openssl rand -hex 32) --from-literal=notifier-token=$(openssl rand -hex 32) --dry-run=client -o name
# secret/taskflow-auth-that
Dựng thử với --set auth.existingSecret=taskflow-auth-that thì không có kind: Secret nào, chín chỗ tham chiếu đều trỏ vào Secret đó. Để trống (mặc định, tiện cho cụm dev) thì chart tự sinh:
- charts/taskflow/templates/secret.yaml
{{- if not .Values.auth.existingSecret }}
{{- $name := include "taskflow.secretName" . }}
{{- /* lookup đọc Secret đang có trên cụm; helm template không nối cụm nên luôn rỗng */}}
{{- $old := (lookup "v1" "Secret" .Release.Namespace $name).data | default dict }}
apiVersion: v1
kind: Secret
metadata:
name: {{ $name }}
# ... labels
annotations:
# helm uninstall giữ lại Secret: volume PostgreSQL còn thì mật khẩu cũ vẫn cần
helm.sh/resource-policy: keep
type: Opaque
data:
{{- range $key, $length := dict "postgres-password" 24 "redis-password" 24 "jwt-secret" 48 "notifier-token" 48 }}
{{ $key }}: {{ index $old $key | default (randAlphaNum $length | b64enc) }}
{{- end }}
{{- end }}
Chỉ có randAlphaNum thì mỗi helm upgrade lại đổi JWT secret (người dùng bị đăng xuất) và mật khẩu, trong khi PostgreSQL giữ mật khẩu cũ trong volume. lookup đọc Secret đang có để giữ giá trị cũ, nhưng chỉ chạy khi Helm nói chuyện với API server: helm template, --dry-run=client luôn nhận rỗng và in mật khẩu mới mỗi lần (đừng kubectl apply kết quả đó), --dry-run=server mới đọc Secret thật (kiểm tra ở phần 6).
Migration bằng Helm hook
Hook là resource có annotation helm.sh/hook: không thuộc release thông thường, Helm tạo nó ở một thời điểm trong vòng đời và chờ nó xong.
- charts/taskflow/templates/migrate-job.yaml (một phần)
annotations:
"helm.sh/hook": post-install,pre-upgrade
# nhiều hook cùng giai đoạn chạy theo weight tăng dần
"helm.sh/hook-weight": "0"
# xóa Job cũ trước khi tạo Job mới; Job thành công thì xóa luôn, lỗi thì giữ để đọc log
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
spec:
# ... backoffLimit, podFailurePolicy (Bài 20), init container wait-postgres (Bài 21)
args: ["-migrate"]
env:
{{- include "taskflow.connectionEnv" . | nindent 12 }}
Trong đó:
pre-upgrade: Helm tạo Job, chờCompleterồi mới cập nhật Deployment; Job lỗi thì upgrade dừng, Pod cũ vẫn chạy. Đúng thứ tự "migration trước" của Bài 20.- Lần cài đầu là
post-install, không phảipre-install: hookpre-installchạy khi chưa có Secret haytaskflow-postgres.post-installchạy sau khi mọi resource đã tạo,wait-postgreschờ PostgreSQL lên; trong lúc đó Pod API restart vài lần như Bài 21. hook-weightsắp thứ tự nhiều hook cùng giai đoạn (nhỏ chạy trước).before-hook-creationcần vì Pod template của Job không sửa được;hook-succeededdọn Job thành công thay chottlSecondsAfterFinished.helm rollbackkhông chạy hook này: migration của TaskFlow chỉ có chiều lên, schema mới phải dùng được cho code cũ.
Xem thêm các loại hook của Helm.
5. Kiểm tra và cài lên cụm.
values.schema.json là JSON Schema của values, Helm kiểm tra ở mọi lệnh lint, template, install, upgrade. Bản của mình chỉ ràng buộc vài chỗ dễ sai, VD api.replicas là số nguyên ≥ 1, mọi giá trị trong config là chuỗi:
helm lint charts/taskflow
# ...
# 1 chart(s) linted, 0 chart(s) failed
helm lint charts/taskflow --set api.replicas=0
# ...
# [ERROR] values.yaml: - at '/api/replicas': minimum: got 0, want 1
# ...
# Error: 1 chart(s) linted, 1 chart(s) failed
helm template taskflow charts/taskflow --set config.TASKFLOW_WORKERS=4 > /dev/null
# Error: values don't meet the specifications of the schema(s) in the following chart(s):
# taskflow:
# - at '/config/TASKFLOW_WORKERS': got number, want string
--set đoán kiểu nên 4 thành số, schema chặn lại trước khi lọt vào cụm; dùng --set-string hoặc ghi trong file values. File values cho lần cài song song này (file tạm, không commit):
- taskflow-helm.yaml
# Cài chart song song với stack Kustomize (namespace taskflow) trên cùng cụm kind
gateway:
hostname: helm.taskflow.local
config:
TASKFLOW_CORS_ORIGIN: http://helm.taskflow.local:8080
api:
replicas: 2
helm template ... -f taskflow-helm.yaml cho ra 16 resource (3 Deployment, 4 Service, StatefulSet, Gateway, HTTPRoute, Job, Pod test...), helm install ... --dry-run=server gửi chúng lên API server kiểm tra rồi báo Dry run complete. Giờ cài thật:
helm install taskflow charts/taskflow -n taskflow-helm --create-namespace -f taskflow-helm.yaml
# NAME: taskflow
# ...
# STATUS: deployed
# REVISION: 1
# DESCRIPTION: Install complete
# NOTES:
# TaskFlow 0.53.0 đã được cài vào namespace taskflow-helm.
# ...
kubectl -n taskflow-helm rollout status deploy/taskflow-api --timeout=300s
# ...
# deployment "taskflow-api" successfully rolled out
curl -s --resolve helm.taskflow.local:8080:127.0.0.1 http://helm.taskflow.local:8080/ready
# ok
curl -s --resolve taskflow.local:8080:127.0.0.1 http://taskflow.local:8080/ready
# ok
install mất 13 giây vì Helm 4 mặc định chờ hook: event của namespace có job/taskflow-migrate tạo Pod rồi Job completed, xong Helm mới trả về (Job thành công bị xóa ngay); NOTES lấy từ templates/NOTES.txt. Hai Gateway dùng chung port 8000 của Traefik, phân biệt bằng hostname: request tới helm.taskflow.local chỉ hiện trong log Pod của taskflow-helm, đăng ký, đăng nhập user mới qua đó chạy bình thường.
Chú ý: đừng thêm --wait vào lần cài đầu. Thử --wait --timeout 2m thì nhận INSTALLATION FAILED: resource Deployment/taskflow-helm/taskflow-api not ready: Helm chờ Deployment sẵn sàng rồi mới chạy post-install, còn taskflow-api đứng CrashLoopBackOff ("database còn migration chưa chạy") vì Job chưa được tạo. upgrade thì dùng --wait được.
kubectl -n taskflow-helm get deploy -L app.kubernetes.io/instance,app.kubernetes.io/managed-by
# NAME READY UP-TO-DATE AVAILABLE AGE INSTANCE MANAGED-BY
# taskflow-api 2/2 2 2 34s taskflow Helm
# taskflow-notifier 1/1 1 1 34s taskflow Helm
# taskflow-redis 1/1 1 1 34s taskflow Helm
Cùng lệnh trong namespace taskflow cho hai cột trống: Kustomize không đặt hai label này. Helm còn ghi annotation meta.helm.sh/release-name, meta.helm.sh/release-namespace. kubectl describe pod của API cho thấy DATABASE_URL: postgres://taskflow:$(POSTGRES_PASSWORD)@taskflow-postgres:5432/taskflow?sslmode=disable và POSTGRES_PASSWORD: <set to the key 'postgres-password' in secret 'taskflow-auth'>: mật khẩu thật chỉ nằm trong Secret.
6. Upgrade, rollback và helm test.
Build image 0.53.1 bằng scripts/load-image.sh như Bài 10, rồi nâng cấp, lần này có --wait:
helm upgrade taskflow charts/taskflow -n taskflow-helm -f taskflow-helm.yaml --set image.tag=0.53.1 --wait --timeout 5m
# Release "taskflow" has been upgraded. Happy Helming!
# ...
# REVISION: 2
# ...
kubectl -n taskflow-helm get events --sort-by=.lastTimestamp | grep -E 'job/taskflow-migrate|replicaset/taskflow-api|deployment/taskflow-api'
# ...
# 11s Normal SuccessfulCreate job/taskflow-migrate Created pod: taskflow-migrate-kpqbd
# 7s Normal Completed job/taskflow-migrate Job completed
# 7s Normal ScalingReplicaSet deployment/taskflow-api Scaled up replica set taskflow-api-79bf999c89 from 0 to 1
# ...
helm history taskflow -n taskflow-helm
# REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION
# 1 Wed Nov 25 18:10:44 2026 superseded taskflow-0.1.0 0.53.0 Install complete
# 2 Wed Nov 25 18:12:12 2026 deployed taskflow-0.1.0 0.53.0 Upgrade complete
Job migration của image mới xong rồi Deployment mới tạo ReplicaSet mới, api và notifier lên 0.53.1, chỉ bằng một lệnh. Cột APP VERSION vẫn 0.53.0 vì đọc từ Chart.yaml: phát hành thật thì tăng appVersion (và version), vì --set chỉ sống trong một lần chạy (Bài 23).
helm rollback taskflow 1 -n taskflow-helm --wait --timeout 5m
# Rollback was a success! Happy Helming!
helm history có thêm revision 3 "Rollback to 1", Pod về 0.53.0; event vẫn chỉ có 2 lần tạo Job (cài, upgrade), rollback không chạy migration. Tiếp theo là checksum/config, đổi log level:
helm upgrade taskflow charts/taskflow -n taskflow-helm -f taskflow-helm.yaml --set config.TASKFLOW_LOG_LEVEL=debug --wait --timeout 5m | head -6
# ...
# REVISION: 4
kubectl -n taskflow-helm get rs -l app.kubernetes.io/part-of=taskflow
# NAME DESIRED CURRENT READY AGE
# ...
# taskflow-api-b487c75c 2 2 2 6s
# taskflow-notifier-76655f5488 1 1 1 2m51s
# ...
kubectl -n taskflow-helm logs -l pod-template-hash=b487c75c --tail=-1 | grep -o '"log_level":"[A-Z]*"'
# "log_level":"DEBUG"
# "log_level":"DEBUG"
Chỉ taskflow-api có ReplicaSet mới, notifier không dùng ConfigMap nên đứng yên, namespace vẫn chỉ có một ConfigMap. Sau bốn revision, kiểm tra lookup bằng cách băm postgres-password (không in mật khẩu ra):
kubectl -n taskflow-helm get secret taskflow-auth -o jsonpath='{.data.postgres-password}' | shasum -a 256 | cut -c1-16
# d0558aeb4e3c801d
helm upgrade taskflow charts/taskflow -n taskflow-helm -f taskflow-helm.yaml --set config.TASKFLOW_LOG_LEVEL=debug --dry-run=client | awk '/postgres-password:/ {printf "%s", $2}' | shasum -a 256 | cut -c1-16
# 90406225fd05feec
helm upgrade taskflow charts/taskflow -n taskflow-helm -f taskflow-helm.yaml --set config.TASKFLOW_LOG_LEVEL=debug --dry-run=server | awk '/postgres-password:/ {printf "%s", $2}' | shasum -a 256 | cut -c1-16
# d0558aeb4e3c801d
Hash trên cụm vẫn là giá trị lúc cài (user đăng ký từ đầu vẫn đăng nhập được); dry-run phía client sinh mật khẩu khác, phía server giữ đúng giá trị cũ. Cuối cùng, Pod trong tests/test-ready.yaml chạy wget -qO- http://taskflow-api/ready (busybox:1.37), có annotation helm.sh/hook: test nên chỉ được tạo khi gọi helm test:
helm test taskflow -n taskflow-helm --logs
# ...
# TEST SUITE: taskflow-test-ready
# ...
# Phase: Succeeded
#
# POD LOGS: taskflow-test-ready (wget)
# ok
helm get values chỉ có api.replicas, config, gateway.hostname: không mật khẩu nào trong values hay release Secret.
7. Đóng gói chart và dọn dẹp.
helm package charts/taskflow tạo taskflow-0.1.0.tgz theo version của chart, bỏ file khớp .helmignore (repo thêm *.tgz vào .gitignore); file này helm install trực tiếp được. Để chia sẻ thì đẩy lên OCI registry như image (helm registry login ghcr.io, helm push taskflow-0.1.0.tgz oci://ghcr.io/toidicode/charts), người dùng cài bằng oci://ghcr.io/toidicode/charts/taskflow --version 0.1.0 như chart Traefik ở Bài 23; sửa chart thì tăng version. Series không đẩy chart (lý do ở phần 8). Dọn namespace thử:
helm uninstall taskflow -n taskflow-helm --wait
# These resources were kept due to the resource policy:
# [Secret] taskflow-auth
#
# release "taskflow" uninstalled
kubectl -n taskflow-helm get all,pvc,secret
# NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS VOLUMEATTRIBUTESCLASS AGE
# persistentvolumeclaim/data-taskflow-postgres-0 Bound pvc-632189ed-a630-481b-8205-8444ae4db393 1Gi RWO standard <unset> 3m46s
#
# NAME TYPE DATA AGE
# secret/taskflow-auth Opaque 4 3m47s
kubectl delete namespace taskflow-helm
# namespace "taskflow-helm" deleted
PVC của volumeClaimTemplates do StatefulSet tạo, Helm không quản lý nên không xóa (Bài 19); Secret ở lại để cài lại cùng tên release thì lookup lấy đúng mật khẩu khớp với dữ liệu đó. Xóa namespace là mất cả hai. Stack Kustomize không bị ảnh hưởng: kubectl diff -k kustomize/overlays/dev trả exit 0, taskflow.local vẫn trả ok.
8. Kustomize hay Helm?
| Tiêu chí | Kustomize (Bài 22) | Helm chart (bài này) |
|---|---|---|
| Đọc, review | Dễ: file nào cũng là manifest hợp lệ | Phải helm template mới thấy kết quả |
| Ghép chuỗi, bật tắt resource | Không (mật khẩu lặp hai chỗ) | Có (printf, if, range) |
| Config đổi thì rollout | Hash suffix, giữ ConfigMap cũ | checksum/config, một ConfigMap |
| Migration | Tự chạy Job trước apply -k | Hook pre-upgrade |
| Lịch sử, rollback, xóa resource thừa | Không (git, rollout undo, apply không prune) | Revision, helm rollback, upgrade xóa resource bị bỏ |
| Phân phối cho người khác | Kém: người dùng phải viết overlay | Tốt: package, OCI, values có schema |
Hai công cụ không loại trừ nhau (Helm có post-renderer chạy Kustomize trên kết quả của chart). Quy tắc thực tế: phần mềm người khác viết thì dùng chart chính thức; ứng dụng của mình, vài môi trường mình kiểm soát thì Kustomize đủ và dễ đọc hơn; phát hành cho nhiều người cài thì viết chart.
Quyết định của series: stack chính của TaskFlow vẫn là Kustomize. Bài 31 (k3s) dùng kustomize/overlays/prod, Bài 32 để Argo CD đồng bộ thư mục đó, CI sửa dòng newTag, Job migration thành hook PreSync của Argo CD. Ngoài việc overlay prod đã có, Argo CD chỉ dựng chart bằng helm template rồi tự quản lý vòng đời: lookup luôn rỗng (Secret tự sinh đổi ở mỗi lần so sánh, bắt buộc phải dùng existingSecret), hook Helm được đổi sang hook của Argo CD (pre-upgrade thành PreSync, post-install thành PostSync), và Argo CD không phân biệt cài với nâng cấp, lần nào cũng là sync. charts/taskflow ở lại repo làm cách cài thứ hai, README có hướng dẫn cài song song như trong bài.
Code đầy đủ của series sau bài này nằm ở tag bai-24 trên GitHub; các thay đổi của riêng bài này: so sánh bai-23...bai-24.
9. Lời kết.
Như vậy mình đã cùng mọi người viết Helm chart cho TaskFlow: values và schema, template, helper cho tên và selector, checksum/config, một mật khẩu cho cả database lẫn URL với existingSecret hoặc lookup, migration bằng hook, lint, upgrade, rollback, test, package, và so sánh với Kustomize. Bài sau mình sẽ cài metrics-server và dùng HorizontalPodAutoscaler để taskflow-api tự scale theo CPU, cùng những giới hạn đã ghi lại từ các bài trước: ResourceQuota 20 Pod, volume upload trên một node và số kết nối PostgreSQL.
Đăng ký nhận tin.
Chúng tôi chỉ gửi tối đa 2 lần trên 1 tháng. Tuyên bố không spam mail!





0 Comments