Helm Charts
Helm 部署 GKE CronJob
Table Of Content
- 初始化指令:
- templates/cronjob.yaml 結構
- templates/\_helpers.tpl 結構
- values.yaml 結構
- env => 部屬的環境(必填),可填值 dev test staging prod
- type => 部屬的類型(必填),可填值 api job frontend
- dept => 部門的單位(必填),可填值 platform outside interface gt1
- product => 服務名稱(必填),例如: bbchat schedule
- repo => 部屬服務的 repo 名稱(必填),例如: imctl_api, imctl_web
- This is a YAML-formatted file.
- Declare variables to be passed into your templates.
- helm lint 檢查
- helm 起服務
- 更新 Pod image 和 tag
- 列出 helm 在線上的服務
- 刪除 helm list 中的內容
- 相關資源
程式範例: GKE-CronJob
初始化指令:
helm create helm-cronjob
templates/cronjob.yaml 結構
apiVersion: batch/v1
kind: CronJob
metadata:
{{- if .Values.labels }}
labels:
{{- include "labels" . | indent 4 }}
{{- end }}
# Cronjob name
name: {{ .Values.job.name }}
# namespace
namespace: {{ .Values.job.namespace | default "default" }}
spec:
schedule: {{ .Values.job.schedule | toYaml | default "* * * * *" }}
concurrencyPolicy: Allow
suspend: false
failedJobsHistoryLimit: {{ .Values.job.failedJobsHistoryLimit | default 10 }}
successfulJobsHistoryLimit: {{ .Values.job.successfulJobsHistoryLimit | default 10 }}
jobTemplate:
spec:
template:
metadata:
{{- if .Values.labels }}
labels:
{{- include "labels" . | indent 12 }}
{{- end }}
spec:
containers:
- name: {{ .Values.job.name }}
image: {{ .Values.job.image.repository | default "nginx:latest" }}
imagePullPolicy: {{ .Values.job.image.imagePullPolicy | default "Always" }}
restartPolicy: OnFailure
templates/_helpers.tpl 結構
{{/*----- labels 模板,通用給 deployment service 確保一致性 -----*/}}
{{- define "labels" }}
{{- with .Values.labels }}
env: {{ .env }}
type: {{ .type }}
dept: {{ .dept }}
product: {{ .product }}
repo: {{ .repo }}
{{- if .tag }}
tag: {{ .tag }}
{{- end }}
{{- end }}
{{- end }}
values.yaml 結構
# env => 部屬的環境(必填),可填值 dev test staging prod
# type => 部屬的類型(必填),可填值 api job frontend
# dept => 部門的單位(必填),可填值 platform outside interface gt1
# product => 服務名稱(必填),例如: bbchat schedule
# repo => 部屬服務的 repo 名稱(必填),例如: imctl_api, imctl_web
labels:
env: dev
type: cronjob
dept: rpa
product: schedule
repo: cronjob-test
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
job:
# first cron
name: "hello-world"
image:
repository: eugeneyiew128/gke-practice:dev_2024031912
imagePullPolicy: Always
namespace: gke-test-f2e
schedule: "* * * * *"
failedJobsHistoryLimit: 1
successfulJobsHistoryLimit: 3
concurrencyPolicy: Allow
restartPolicy: OnFailure
helm lint 檢查
helm lint app-helm/
helm 起服務
helm install <服務名稱> app-helm
更新 Pod image 和 tag
helm upgrade --reuse-values --set image.repository=<image url> --set image.tag=<image tag> <deployment name> <helm folder>
ex: helm upgrade --reuse-values --set job.image.repository=eugeneyiew128/gke-practice:cronjob4ede4a87 <服務名稱> app-helm
列出 helm 在線上的服務
helm ls
刪除 helm list 中的內容
helm delete gke-test-f2e
or
helm uninstall test-cron-job