Files
cloud-configuration/helm/template/templates/_deployment.yaml
T

129 lines
4.7 KiB
YAML

{{- define "template.deployment" -}}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "template.fullname" . }}
labels:
{{- include "template.labels" . | nindent 4 }}
annotations:
{{- include "template.annotations" . | nindent 4 }}
spec:
revisionHistoryLimit: {{ .Values.revisionHistoryLimit }}
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "template.selectorLabels" . | nindent 6 }}
template:
metadata:
annotations:
{{- if and $.Values.prometheus.enabled (not $.Values.prometheus.useCRDs) $.Values.application.isSpring }}
prometheus.io/scrape: "true"
prometheus.io/path: /actuator/prometheus
prometheus.io/port: "{{ $.Values.application.actuatorPort }}"
{{- end }}
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- include "template.annotations" . | nindent 8 }}
labels:
{{- include "template.selectorLabels" . | nindent 8 }}
spec:
enableServiceLinks: {{ .Values.enableServiceLinks }}
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "template.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 "latest" }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- if or .Values.secrets .Values.vault.enabled }}
envFrom:
- secretRef:
name: {{ include "template.fullname" . }}
{{- end }}
env:
{{- if .Values.application.isSpring }}
- name: SPRING_PROFILES_ACTIVE
value: {{ .Values.application.profile }}
{{- end}}
{{- range .Values.environment }}
- name: {{ .name }}
value: {{ tpl (quote .value) $ }}
{{- end }}
{{- if .Values.application.isSpring }}
volumeMounts:
- mountPath: /tmp
name: tmp
{{- end }}
ports:
- name: http
containerPort: {{ .Values.application.port }}
protocol: TCP
{{- if .Values.application.isSpring }}
- name: http-actuator
containerPort: {{ .Values.application.actuatorPort }}
protocol: TCP
{{- end }}
{{- if .Values.livenessProbe.enabled }}
livenessProbe:
httpGet:
path: {{ .Values.livenessProbe.path }}
port: {{ .Values.livenessProbe.port }}
initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
{{- end }}
{{- if .Values.readinessProbe.enabled }}
readinessProbe:
httpGet:
path: {{ .Values.readinessProbe.path }}
port: {{ .Values.readinessProbe.port }}
initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }}
periodSeconds: {{ .Values.readinessProbe.periodSeconds }}
timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }}
{{- end }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.containerSpec }}
{{- toYaml . | nindent 10 }}
{{- end }}
{{/*
Due to the asynchronous way Kubernetes shuts down applications there is a period of
time when requests can be sent to the application while an application is being terminated.
To deal with this we can configure a pre-stop sleep to allow enough time for requests to
stop being routed to the application before it is terminated.
*/}}
lifecycle:
preStop:
exec:
command: [ "sh", "-c", "sleep 10" ]
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if .Values.application.isSpring }}
volumes:
- name: tmp
emptyDir:
medium: Memory
{{- end }}
{{- with .Values.podSpec }}
{{- toYaml . | nindent 6 }}
{{- end }}
{{- end }}