查看HELM模板指南写一个简单的通用模板,包括deployment和service,一个values-xxx.yaml为一个微服务,要求环境变量,镜像,健康检查,端口,名称,副本数,资源限制,调度,拉取密钥,滚动更新策略可动态变更
时间: 2024-05-07 12:21:11 浏览: 179
好的,以下是一个简单的通用模板,包括deployment和service:
```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Values.name }}
spec:
replicas: {{ .Values.replicas }}
selector:
matchLabels:
app: {{ .Values.name }}
template:
metadata:
labels:
app: {{ .Values.name }}
spec:
containers:
- name: {{ .Values.name }}
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
ports:
- containerPort: {{ .Values.port }}
env:
{{- range $key, $value := .Values.env }}
- name: {{ $key }}
value: {{ $value }}
{{- end }}
readinessProbe:
httpGet:
path: /health
port: {{ .Values.port }}
livenessProbe:
httpGet:
path: /health
port: {{ .Values.port }}
resources:
limits:
cpu: {{ .Values.resources.cpu }}
memory: {{ .Values.resources.memory }}
requests:
cpu: {{ .Values.resources.cpu }}
memory: {{ .Values.resources.memory }}
imagePullSecrets:
- name: {{ .Values.imagePullSecret }}
{{- if .Values.nodeSelector }}
nodeSelector:
{{- range $key, $value := .Values.nodeSelector }}
{{ $key }}: {{ $value }}
{{- end }}
{{- end }}
{{- if .Values.tolerations }}
tolerations:
{{- range .Values.tolerations }}
- key: "{{ .key }}"
operator: "{{ .operator }}"
value: "{{ .value }}"
effect: "{{ .effect }}"
tolerationSeconds: "{{ .tolerationSeconds }}"
{{- end }}
{{- end }}
imagePullSecrets:
- name: {{ .Values.imagePullSecret }}
{{- if .Values.affinity }}
affinity:
{{- if .Values.affinity.nodeAffinity }}
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
{{- range $key, $value := .Values.affinity.nodeAffinity.required }}
- key: {{ $key }}
operator: In
values:
{{- range $value }}
- {{ . }}
{{- end }}
{{- end }}
{{- end }}
{{- if .Values.affinity.podAffinity }}
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
{{- range $key, $value := .Values.affinity.podAffinity.required }}
- labelSelector:
matchExpressions:
{{- range $k, $v := $value }}
- key: {{ $k }}
operator: In
values:
{{- range $v }}
- {{ . }}
{{- end }}
{{- end }}
topologyKey: {{ $key }}
{{- end }}
{{- end }}
{{- if .Values.affinity.podAntiAffinity }}
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
{{- range $key, $value := .Values.affinity.podAntiAffinity.required }}
- labelSelector:
matchExpressions:
{{- range $k, $v := $value }}
- key: {{ $k }}
operator: In
values:
{{- range $v }}
- {{ . }}
{{- end }}
{{- end }}
topologyKey: {{ $key }}
{{- end }}
{{- end }}
{{- end }}
---
apiVersion: v1
kind: Service
metadata:
name: {{ .Values.name }}
spec:
ports:
- name: http
port: {{ .Values.port }}
targetPort: {{ .Values.port }}
selector:
app: {{ .Values.name }}
type: ClusterIP
```
并且一个values-xxx.yaml为一个微服务,要求环境变量,镜像,健康检查,端口,名称,副本数,资源限制,调度,拉取密钥,滚动更新策略可动态变更,如下所示:
```yaml
name: example-service
replicas: 1
image:
repository: example/image
tag: latest
port: 8080
env:
ENV_VAR_1: "value1"
ENV_VAR_2: "value2"
resources:
cpu: 500m
memory: 512Mi
nodeSelector:
kubernetes.io/hostname: node1
tolerations:
- key: "example-key"
operator: "Equal"
value: "example-value"
effect: "NoSchedule"
tolerationSeconds: 3600
affinity:
nodeAffinity:
required:
node-role.kubernetes.io/example: ["true"]
podAffinity:
required:
topology.kubernetes.io/zone: ["zone1"]
podAntiAffinity:
required:
topology.kubernetes.io/zone: ["zone2"]
imagePullSecret: example-secret
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
```
阅读全文