Resource Templates Best Practices
You'll learn how to structure your Helm templates for Deployments, Services, and ConfigMaps following Kubernetes and Helm conventions to create maintainable, consistent charts.
Why Structure Matters
Think of resource templates like a filing system: if everyone organizes their files differently, finding and maintaining documents becomes chaotic. Following consistent patterns across your Deployment, Service, and ConfigMap templates makes your Helm charts predictable and easier to manage.
Core Best Practices
Consistent Metadata Structure
Always use the same pattern for metadata blocks. Include the release name in resource names using {{ .Release.Name }} and apply standard labels:
metadata:
name: {{ .Release.Name }}-myapp
labels:
app.kubernetes.io/name: {{ .Chart.Name }}
app.kubernetes.io/instance: {{ .Release.Name }}
Template File Organization
Name your template files clearly: deployment.yaml, service.yaml, configmap.yaml. Keep each resource type in its own file for clarity.
Conditional Resource Creation
Use conditionals to make resources optional:
{{- if .Values.configMap.enabled }}
apiVersion: v1
kind: ConfigMap
# ...
{{- end }}
Selector Consistency
Ensure your Service selectors match your Deployment labels exactly—use the same helper template or variables for both to avoid mismatches.
Values File Alignment
Structure your values.yaml to mirror your templates: group related settings under deployment:, service:, and configMap: keys.
Key Takeaway: Consistent structure across your resource templates—standardized metadata, clear naming conventions, aligned selectors, and organized values—transforms individual YAML files into a cohesive, maintainable Helm chart that follows both Kubernetes and Helm community conventions.