Tasks 10-11: podAffinity+nodeAffinity 合并到同一 affinity 块; audit/shared-infra 走 tier;Chart.yaml 1.1.0→1.2.0。
94 lines
2.9 KiB
Smarty
94 lines
2.9 KiB
Smarty
{{/*
|
|
公共模板:前端 Deployment + Service
|
|
可选 podAffinity(四胞胎用:前端和后端同节点)
|
|
|
|
参数:
|
|
name - 服务名(agent-web-0 / sso-web ...)
|
|
image - 镜像名
|
|
port - 端口(默认 80)
|
|
basePath - vite base path
|
|
affinity - 要亲和的目标服务名(如 "agent-0"),空则不配亲和
|
|
root - $ (root context)
|
|
*/}}
|
|
{{- define "mixingx.frontend" -}}
|
|
{{- $root := .root -}}
|
|
{{- $port := .port | default 80 -}}
|
|
---
|
|
# Deployment: {{ .name }}
|
|
apiVersion: apps/v1
|
|
kind: Deployment
|
|
metadata:
|
|
name: {{ .name }}-deployment
|
|
labels:
|
|
app.kubernetes.io/name: mixingx
|
|
app.kubernetes.io/instance: {{ $root.Release.Name }}
|
|
app.kubernetes.io/component: {{ .name }}
|
|
spec:
|
|
replicas: 1
|
|
selector:
|
|
matchLabels:
|
|
app.kubernetes.io/component: {{ .name }}
|
|
template:
|
|
metadata:
|
|
labels:
|
|
app.kubernetes.io/component: {{ .name }}
|
|
spec:
|
|
{{- if .nodeName }}
|
|
nodeName: {{ .nodeName }}
|
|
{{- else if .affinity }}
|
|
# 四胞胎:前端必须和后端同节点(podAffinity + 点位/tier nodeAffinity 合并到同一 affinity 块)
|
|
affinity:
|
|
podAffinity:
|
|
requiredDuringSchedulingIgnoredDuringExecution:
|
|
- labelSelector:
|
|
matchLabels:
|
|
app.kubernetes.io/component: {{ .affinity }}
|
|
topologyKey: kubernetes.io/hostname
|
|
{{- if .pointAffinity }}
|
|
{{ include "mixingx.pointNodeAffinity" (dict "affinity" .pointAffinity "root" $root) }}
|
|
{{- else if and $root.Values.tier $root.Values.tier.enabled }}
|
|
{{ include "mixingx.tierNodeAffinity" (dict "role" .tierRole "root" $root) }}
|
|
{{- end }}
|
|
{{- else if .pointAffinity }}
|
|
{{ include "mixingx.pointAffinity" (dict "affinity" .pointAffinity "root" $root) }}
|
|
{{- else if and $root.Values.tier $root.Values.tier.enabled }}
|
|
{{ include "mixingx.tierAffinity" (dict "role" .tierRole "root" $root) }}
|
|
{{- end }}
|
|
containers:
|
|
- name: {{ .name }}
|
|
image: {{ $root.Values.registry }}/{{ .image }}:{{ $root.Values.tag | default "latest" }}
|
|
imagePullPolicy: IfNotPresent
|
|
ports:
|
|
- name: http
|
|
containerPort: {{ $port }}
|
|
protocol: TCP
|
|
env:
|
|
# 时区(部署地域覆盖,优先级 > 镜像内 /etc/localtime)
|
|
- name: TZ
|
|
value: "{{ $root.Values.timezone | default "Asia/Shanghai" }}"
|
|
- name: VITE_BASE_PATH
|
|
value: "{{ .basePath }}"
|
|
- name: PORT
|
|
value: "{{ $port }}"
|
|
|
|
---
|
|
# Service: {{ .name }}
|
|
apiVersion: v1
|
|
kind: Service
|
|
metadata:
|
|
name: {{ .name }}-service
|
|
labels:
|
|
app.kubernetes.io/name: mixingx
|
|
app.kubernetes.io/component: {{ .name }}
|
|
mixingx.io/role: web
|
|
mixingx.io/node-id: {{ .name }}
|
|
spec:
|
|
selector:
|
|
app.kubernetes.io/component: {{ .name }}
|
|
ports:
|
|
- name: http
|
|
port: {{ $port }}
|
|
targetPort: http
|
|
protocol: TCP
|
|
{{- end -}}
|