Skip to content
Clone
main
192 lines 6.6 KB YAML
{{- if .Values.apihost.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ printf "%s-apihost" (include "gitdata.fullname" .) }}
labels:
{{- include "gitdata.labels" . | nindent 4 }}
app.kubernetes.io/component: apihost
spec:
{{- if .Values.apihost.autoscaling.enabled }}
# 开着 HPA 时不要声明 replicas:HPA 通过 /scale 子资源写这个字段,
# kube-controller-manager 于是成为它的 manager;helm 的 server-side apply
# 再写一次就会报 conflict with "kube-controller-manager" with subresource
# "scale": .spec.replicas —— 升级直接失败;而且就算写进去,也会把已经扩上
# 去的副本数硬拉回 minReplicas。省略即让出所有权:SSA 不会因此把字段清成
# 默认值,副本数继续由 scale 子资源持有。
{{- else }}
replicas: {{ .Values.apihost.replicaCount }}
{{- end }}
revisionHistoryLimit: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: {{ .Values.apihost.maxSurge }}
maxUnavailable: {{ .Values.apihost.maxUnavailable }}
selector:
matchLabels:
{{- include "gitdata.selectorLabels" . | nindent 6 }}
app.kubernetes.io/component: apihost
template:
metadata:
labels:
{{- include "gitdata.selectorLabels" . | nindent 8 }}
app.kubernetes.io/component: apihost
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
annotations:
checksum/env: {{ toYaml .Values.config.env | sha256sum }}
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
serviceAccountName: {{ include "gitdata.serviceAccountName" . }}
{{- include "gitdata.imagePullSecrets" . | nindent 6 }}
terminationGracePeriodSeconds: 45
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
{{- if or (eq .Values.apihost.podAntiAffinity "soft") (eq .Values.apihost.podAntiAffinity "hard") }}
affinity:
{{- include "gitdata.podAntiAffinity" (dict "ctx" . "mode" .Values.apihost.podAntiAffinity "component" "apihost") | nindent 8 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
containers:
- name: apihost
image: {{ include "gitdata.image" . }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
args: ["app", "serve"]
{{- include "gitdata.envFrom" . | nindent 10 }}
env:
{{- include "gitdata.env" . | nindent 12 }}
{{- with .Values.apihost.extraEnv }}
{{- toYaml . | nindent 12 }}
{{- end }}
ports:
- name: http
containerPort: {{ .Values.apihost.port }}
- name: rpc
containerPort: {{ .Values.apihost.rpcPort }}
livenessProbe:
httpGet: { path: /healthz, port: http }
initialDelaySeconds: 10
periodSeconds: 15
timeoutSeconds: 3
readinessProbe:
httpGet: { path: /readyz, port: http }
initialDelaySeconds: 5
periodSeconds: 10
timeoutSeconds: 3
failureThreshold: 3
lifecycle:
preStop:
exec:
command: ["/bin/sh", "-c", "sleep 5"]
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
resources:
{{- toYaml .Values.apihost.resources | nindent 12 }}
volumeMounts:
- name: repos
mountPath: {{ .Values.persistence.repos.mountPath }}
{{- if .Values.identityKey.secretName }}
- name: identity-keys
mountPath: {{ .Values.identityKey.mountPath }}
readOnly: true
{{- end }}
volumes:
{{- if .Values.identityKey.secretName }}
- name: identity-keys
secret:
secretName: {{ .Values.identityKey.secretName }}
{{- end }}
- name: repos
{{- if .Values.persistence.repos.existingClaim }}
persistentVolumeClaim:
claimName: {{ .Values.persistence.repos.existingClaim }}
{{- else if .Values.persistence.repos.enabled }}
persistentVolumeClaim:
claimName: {{ printf "%s-repos" (include "gitdata.fullname" .) }}
{{- else }}
emptyDir: {}
{{- end }}
---
apiVersion: v1
kind: Service
metadata:
name: {{ printf "%s-apihost" (include "gitdata.fullname" .) }}
labels:
{{- include "gitdata.labels" . | nindent 4 }}
app.kubernetes.io/component: apihost
spec:
type: ClusterIP
selector:
{{- include "gitdata.selectorLabels" . | nindent 4 }}
app.kubernetes.io/component: apihost
ports:
- name: http
port: {{ .Values.apihost.port }}
targetPort: http
- name: rpc
port: {{ .Values.apihost.rpcPort }}
targetPort: rpc
{{- if .Values.apihost.autoscaling.enabled }}
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ printf "%s-apihost" (include "gitdata.fullname" .) }}
labels:
{{- include "gitdata.labels" . | nindent 4 }}
app.kubernetes.io/component: apihost
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ printf "%s-apihost" (include "gitdata.fullname" .) }}
minReplicas: {{ .Values.apihost.autoscaling.minReplicas }}
maxReplicas: {{ .Values.apihost.autoscaling.maxReplicas }}
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Values.apihost.autoscaling.targetCPUUtilizationPercentage }}
{{- if gt (int (.Values.apihost.autoscaling.targetMemoryUtilizationPercentage | default 0)) 0 }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ .Values.apihost.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- with .Values.apihost.autoscaling.behavior }}
behavior:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
{{- if .Values.apihost.pdb.enabled }}
---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: {{ printf "%s-apihost" (include "gitdata.fullname" .) }}
labels:
{{- include "gitdata.labels" . | nindent 4 }}
app.kubernetes.io/component: apihost
spec:
minAvailable: {{ .Values.apihost.pdb.minAvailable }}
selector:
matchLabels:
{{- include "gitdata.selectorLabels" . | nindent 6 }}
app.kubernetes.io/component: apihost
{{- end }}
{{- end }}