Helm是Kubernetes的包管理器。本文介绍Chart开发和管理的最佳实践。 ## Chart结构 ``` mychart/ Chart.yaml values.yaml charts/ templates/ deployment.yaml service.yaml _helpers.tpl ``` ## 模板最佳实践 ```yaml apiVersion: apps/v1 kind: Deployment metadata: name: {{ include "myapp.fullname" . }} labels: {{- include "myapp.labels" . | nindent 4 }} spec: replicas: {{ .Values.replicaCount }} selector: matchLabels: {{- include "myapp.selectorLabels" . | nindent 6 }} template: spec: containers: - name: {{ .Chart.Name }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" ``` ## 发布管理 ```bash helm install myapp ./mychart -n production helm upgrade myapp ./mychart -n production helm rollback myapp 1 -n production ``` 良好的Chart设计让Kubernetes应用的部署和升级变得简单可靠。