feat(k8s): add Kubernetes Helm chart for emailks service
- Create Helm chart structure with Chart.yaml and values.yaml - Add deployment template with container configuration and environment variables - Implement service template for gRPC port exposure - Add service account template with security configuration - Include horizontal pod autoscaler template for scaling capabilities - Add helper templates for naming and label management - Configure SMTP settings as configurable parameters in values.yaml - Set up resource limits and requests for container performance - Implement liveness and readiness probes for health checks - Add support for existing secrets and custom configurations
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
{{- define "emailks.name" -}}
|
||||
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
|
||||
{{- end }}
|
||||
|
||||
{{- define "emailks.fullname" -}}
|
||||
{{- if .Values.fullnameOverride }}
|
||||
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
|
||||
{{- else }}
|
||||
{{- $name := default .Chart.Name .Values.nameOverride }}
|
||||
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
{{- define "emailks.chart" -}}
|
||||
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
|
||||
{{- end }}
|
||||
|
||||
{{- define "emailks.labels" -}}
|
||||
helm.sh/chart: {{ include "emailks.chart" . }}
|
||||
{{ include "emailks.selectorLabels" . }}
|
||||
{{- if .Chart.AppVersion }}
|
||||
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
|
||||
{{- end }}
|
||||
app.kubernetes.io/managed-by: {{ .Release.Service }}
|
||||
{{- end }}
|
||||
|
||||
{{- define "emailks.selectorLabels" -}}
|
||||
app.kubernetes.io/name: {{ include "emailks.name" . }}
|
||||
app.kubernetes.io/instance: {{ .Release.Name }}
|
||||
{{- end }}
|
||||
|
||||
{{- define "emailks.serviceAccountName" -}}
|
||||
{{- if .Values.serviceAccount.create }}
|
||||
{{- default (include "emailks.fullname" .) .Values.serviceAccount.name }}
|
||||
{{- else }}
|
||||
{{- default "default" .Values.serviceAccount.name }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
@@ -0,0 +1,109 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: {{ include "emailks.fullname" . }}
|
||||
labels:
|
||||
{{- include "emailks.labels" . | nindent 4 }}
|
||||
spec:
|
||||
replicas: {{ .Values.replicaCount }}
|
||||
selector:
|
||||
matchLabels:
|
||||
{{- include "emailks.selectorLabels" . | nindent 6 }}
|
||||
template:
|
||||
metadata:
|
||||
{{- with .Values.podAnnotations }}
|
||||
annotations:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
labels:
|
||||
{{- include "emailks.selectorLabels" . | nindent 8 }}
|
||||
{{- with .Values.podLabels }}
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
spec:
|
||||
{{- with .Values.imagePullSecrets }}
|
||||
imagePullSecrets:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
serviceAccountName: {{ include "emailks.serviceAccountName" . }}
|
||||
securityContext:
|
||||
{{- toYaml .Values.podSecurityContext | nindent 8 }}
|
||||
containers:
|
||||
- name: {{ .Chart.Name }}
|
||||
securityContext:
|
||||
{{- toYaml .Values.securityContext | nindent 12 }}
|
||||
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
|
||||
imagePullPolicy: {{ .Values.image.pullPolicy }}
|
||||
ports:
|
||||
- name: grpc
|
||||
containerPort: 50051
|
||||
protocol: TCP
|
||||
env:
|
||||
- name: APP_SMTP_HOST
|
||||
value: {{ required "smtp.host is required" .Values.smtp.host | quote }}
|
||||
- name: APP_SMTP_PORT
|
||||
value: {{ .Values.smtp.port | quote }}
|
||||
- name: APP_SMTP_TLS
|
||||
value: {{ .Values.smtp.tls | quote }}
|
||||
{{- with .Values.smtp.username }}
|
||||
- name: APP_SMTP_USERNAME
|
||||
value: {{ . | quote }}
|
||||
{{- end }}
|
||||
{{- if .Values.existingSecret.name }}
|
||||
- name: APP_SMTP_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: {{ .Values.existingSecret.name }}
|
||||
key: {{ .Values.existingSecret.passwordKey }}
|
||||
{{- else if .Values.smtp.password }}
|
||||
- name: APP_SMTP_PASSWORD
|
||||
value: {{ .Values.smtp.password | quote }}
|
||||
{{- end }}
|
||||
- name: APP_SMTP_FROM_EMAIL
|
||||
value: {{ .Values.smtp.fromEmail | quote }}
|
||||
{{- with .Values.smtp.fromName }}
|
||||
- name: APP_SMTP_FROM_NAME
|
||||
value: {{ . | quote }}
|
||||
{{- end }}
|
||||
{{- with .Values.smtp.replyTo }}
|
||||
- name: APP_SMTP_REPLY_TO
|
||||
value: {{ . | quote }}
|
||||
{{- end }}
|
||||
- name: APP_SMTP_TIMEOUT_SECS
|
||||
value: {{ .Values.smtp.timeoutSecs | quote }}
|
||||
{{- with .Values.smtp.heloName }}
|
||||
- name: APP_SMTP_HELO_NAME
|
||||
value: {{ . | quote }}
|
||||
{{- end }}
|
||||
- name: APP_SMTP_ALLOW_REQUEST_FROM
|
||||
value: {{ .Values.smtp.allowRequestFrom | quote }}
|
||||
- name: APP_SMTP_QUEUE_CAPACITY
|
||||
value: {{ .Values.queue.capacity | quote }}
|
||||
- name: APP_SMTP_LISTEN_ADDR
|
||||
value: {{ .Values.listenAddr | quote }}
|
||||
- name: RUST_LOG
|
||||
value: {{ .Values.logLevel | quote }}
|
||||
livenessProbe:
|
||||
tcpSocket:
|
||||
port: grpc
|
||||
initialDelaySeconds: 5
|
||||
periodSeconds: 10
|
||||
readinessProbe:
|
||||
tcpSocket:
|
||||
port: grpc
|
||||
initialDelaySeconds: 3
|
||||
periodSeconds: 5
|
||||
resources:
|
||||
{{- toYaml .Values.resources | nindent 12 }}
|
||||
{{- with .Values.nodeSelector }}
|
||||
nodeSelector:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
{{- with .Values.affinity }}
|
||||
affinity:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
{{- with .Values.tolerations }}
|
||||
tolerations:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
@@ -0,0 +1,24 @@
|
||||
{{- if .Values.autoscaling.enabled }}
|
||||
apiVersion: autoscaling/v2
|
||||
kind: HorizontalPodAutoscaler
|
||||
metadata:
|
||||
name: {{ include "emailks.fullname" . }}
|
||||
labels:
|
||||
{{- include "emailks.labels" . | nindent 4 }}
|
||||
spec:
|
||||
scaleTargetRef:
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
name: {{ include "emailks.fullname" . }}
|
||||
minReplicas: {{ .Values.autoscaling.minReplicas }}
|
||||
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
|
||||
metrics:
|
||||
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
|
||||
- type: Resource
|
||||
resource:
|
||||
name: cpu
|
||||
target:
|
||||
type: Utilization
|
||||
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
@@ -0,0 +1,15 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: {{ include "emailks.fullname" . }}
|
||||
labels:
|
||||
{{- include "emailks.labels" . | nindent 4 }}
|
||||
spec:
|
||||
type: {{ .Values.service.type }}
|
||||
ports:
|
||||
- port: {{ .Values.service.port }}
|
||||
targetPort: {{ .Values.service.targetPort }}
|
||||
protocol: TCP
|
||||
name: grpc
|
||||
selector:
|
||||
{{- include "emailks.selectorLabels" . | nindent 4 }}
|
||||
@@ -0,0 +1,13 @@
|
||||
{{- if .Values.serviceAccount.create -}}
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: {{ include "emailks.serviceAccountName" . }}
|
||||
labels:
|
||||
{{- include "emailks.labels" . | nindent 4 }}
|
||||
{{- with .Values.serviceAccount.annotations }}
|
||||
annotations:
|
||||
{{- toYaml . | nindent 4 }}
|
||||
{{- end }}
|
||||
automountServiceAccountToken: false
|
||||
{{- end }}
|
||||
Reference in New Issue
Block a user