apiVersion: apps/v1 #指定api版本,此值必須在kubectl apiversion中
kind: Deployment #指定創建資源的角色/類型
metadata: #資源的元數據/屬性
name: {{ include "monitor.fullname" . }} #資源的名字,在同一個namespace中必須唯一
labels: #設定資源的標籤
app.kubernetes.io/name: {{ include "monitor.name" . }}
helm.sh/chart: {{ include "monitor.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app.kubernetes.io/name: {{ include "monitor.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "monitor.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
spec:
containers:
- name: {{ .Chart.Name }} #pod的名稱,必須字段,名稱唯一且對象創建後不可以被修改
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" #鏡像倉庫的路徑/鏡像的名稱:鏡像的標籤
imagePullPolicy: {{ .Values.image.pullPolicy }} #鏡像的下載策略。有三種:Always(總是去倉庫下載) ,Never(從不去倉庫下載) , IfNotPresent(如果本地沒有就去倉庫下載)
# command: [sleep]
# args: [100d]
volumeMounts:
- name: common-config
mountPath: /myapp/config #可以被容器掛載的存儲卷的路徑,路徑不能包含':' 符號
- mountPath: {{.Values.public.mountPath}}
name: coredump
ports: #容器公開的端口列表。在這裏公開端口可以爲系統提供關於容器使用的網絡連接的額外信息,但主要是提供信息。在這裏不指定端口不會阻止該端口被公開。任何監聽容器內默認的“0.0.0.0”地址的端口都可以從網絡訪問
- name: grpc
containerPort: 80 #pod暴露的端口,此端口僅是額外的信息,對端口是否被暴露沒有影響
protocol: TCP #端口的協議
env: #配置env
- name: MY_NODE_NAME #env名稱
valueFrom: #指定env的來源
fieldRef:
fieldPath: spec.nodeName
# livenessProbe:
# httpGet:
# path: /
# port: http
# readinessProbe:
# httpGet:
# path: /
# port: http
resources: #資源的操作(cpu/內存佔用管理)
{{- toYaml .Values.resources | nindent 12 }}
volumes:
- name: common-config
configMap:
name: common-config
- name: coredump
hostPath:
path: {{.Values.public.mountPath}}
{{- with .Values.nodeSelector }}
nodeSelector: #節點選擇器
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity: #節點親和性
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations: #污點和耐性
{{- toYaml . | nindent 8 }}
{{- end }}
⚫️部分解析
apiversion----------------版本選擇
labels----------------------標籤,標註信息,
spec------------------------指定該資源的內容 ,使用一些字段進行描述。
apiversion----------------控制pod部署node
tolerations----------------控制pod部署的條件,允許某些pod在指定的節點上或者不允許指定的pod到指定節點上或者必須要有某些的pod才能調度到指定節點上
參考文獻
【K8s之yaml文件詳解】--------理論
【K8s yaml文件註釋】----------實操
【spec常用字段彙總】----------資源內容的編輯
【關於Affinity和nodeSelector以及Taints與容忍的理解】 —spec中的控制pod運行條件