instruction: Create a Helm chart for a web application with database dependencies
output: Here's a complete Helm chart for a web application with database:
  
  ```yaml
  # Chart.yaml
  apiVersion: v2
  name: web-app
  description: A Helm chart for web application with database
  type: application
  version: 0.1.0
  appVersion: "1.0.0"
  
  dependencies:
  - name: postgresql
   version: 12.1.2
   repository: https://charts.bitnami.com/bitnami
   condition: postgresql.enabled
  - name: redis
   version: 17.4.3
   repository: https://charts.bitnami.com/bitnami
   condition: redis.enabled
  
  ---
  # values.yaml
  replicaCount: 3
  
  image:
   repository: nginx
   pullPolicy: IfNotPresent
   tag: "1.21"
  
  imagePullSecrets: []
  nameOverride: ""
  fullnameOverride: ""
  
  serviceAccount:
   create: true
   annotations: {}
   name: ""
  
  podAnnotations: {}
  podSecurityContext:
   fsGroup: 2000
  
  securityContext:
   capabilities:
   drop:
   - ALL
   readOnlyRootFilesystem: true
   runAsNonRoot: true
   runAsUser: 1000
  
  service:
   type: ClusterIP
   port: 80
   targetPort: 8080
  
  ingress:
   enabled: true
   className: "nginx"
   annotations:
   cert-manager.io/cluster-issuer: "letsencrypt-prod"
   nginx.ingress.kubernetes.io/rate-limit: "100"
   hosts:
   - host: app.example.com
   paths:
   - path: /
   pathType: Prefix
   tls:
   - secretName: app-tls
   hosts:
   - app.example.com
  
  resources:
   limits:
   cpu: 500m
   memory: 512Mi
   requests:
   cpu: 250m
   memory: 256Mi
  
  autoscaling:
   enabled: true
   minReplicas: 2
   maxReplicas: 10
   targetCPUUtilizationPercentage: 80
   targetMemoryUtilizationPercentage: 80
  
  nodeSelector: {}
  tolerations: []
  affinity: {}
  
  env:
   - name: NODE_ENV
   value: "production"
   - name: PORT
   value: "8080"
  
  envFrom:
   - configMapRef:
   name: app-config
   - secretRef:
   name: app-secrets
  
  livenessProbe:
   httpGet:
   path: /health
   port: 8080
   initialDelaySeconds: 30
   periodSeconds: 10
   timeoutSeconds: 5
   failureThreshold: 3
  
  readinessProbe:
   httpGet:
   path: /ready
   port: 8080
   initialDelaySeconds: 5
   periodSeconds: 5
   timeoutSeconds: 3
   failureThreshold: 3
  
  # Database configuration
  postgresql:
   enabled: true
   auth:
   postgresPassword: "changeme"
   database: "webapp"
   username: "webapp"
   password: "webapp123"
   primary:
   persistence:
   enabled: true
   size: 20Gi
   storageClass: "gp2"
  
  redis:
   enabled: true
   auth:
   enabled: true
   password: "redis123"
   master:
   persistence:
   enabled: true
   size: 5Gi
  
  ---
  # templates/deployment.yaml
  apiVersion: apps/v1
  kind: Deployment
  metadata:
   name: {{ include "web-app.fullname" . }}
   labels:
   {{- include "web-app.labels" . | nindent 4 }}
  spec:
   {{- if not .Values.autoscaling.enabled }}
   replicas: {{ .Values.replicaCount }}
   {{- end }}
   selector:
   matchLabels:
   {{- include "web-app.selectorLabels" . | nindent 6 }}
   template:
   metadata:
   annotations:
   checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
   {{- with .Values.podAnnotations }}
   {{- toYaml . | nindent 8 }}
   {{- end }}
   labels:
   {{- include "web-app.selectorLabels" . | nindent 8 }}
   spec:
   {{- with .Values.imagePullSecrets }}
   imagePullSecrets:
   {{- toYaml . | nindent 8 }}
   {{- end }}
   serviceAccountName: {{ include "web-app.serviceAccountName" . }}
   securityContext:
   {{- toYaml .Values.podSecurityContext | nindent 8 }}
   initContainers:
   - name: wait-for-db
   image: postgres:14-alpine
   command:
   - sh
   - -c
   - |
   until pg_isready -h {{ include "web-app.postgresql.fullname" . }} -p 5432; do
   echo "Waiting for database..."
   sleep 2
   done
   containers:
   - name: {{ .Chart.Name }}
   securityContext:
   {{- toYaml .Values.securityContext | nindent 12 }}
   image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
   imagePullPolicy: {{ .Values.image.pullPolicy }}
   ports:
   - name: http
   containerPort: {{ .Values.service.targetPort }}
   protocol: TCP
   env:
   {{- range .Values.env }}
   - name: {{ .name }}
   value: {{ .value | quote }}
   {{- end }}
   - name: DATABASE_URL
   value: "postgresql://{{ .Values.postgresql.auth.username }}:{{ .Values.postgresql.auth.password }}@{{ include "web-app.postgresql.fullname" . }}:5432/{{ .Values.postgresql.auth.database }}"
   - name: REDIS_URL
   value: "redis://:{{ .Values.redis.auth.password }}@{{ include "web-app.redis.fullname" . }}-master:6379"
   {{- with .Values.envFrom }}
   envFrom:
   {{- toYaml . | nindent 8 }}
   {{- end }}
   livenessProbe:
   {{- toYaml .Values.livenessProbe | nindent 12 }}
   readinessProbe:
   {{- toYaml .Values.readinessProbe | nindent 12 }}
   resources:
   {{- toYaml .Values.resources | nindent 12 }}
   volumeMounts:
   - name: tmp
   mountPath: /tmp
   volumes:
   - name: tmp
   emptyDir: {}
   {{- with .Values.nodeSelector }}
   nodeSelector:
   {{- toYaml . | nindent 8 }}
   {{- end }}
   {{- with .Values.affinity }}
   affinity:
   {{- toYaml . | nindent 8 }}
   {{- end }}
   {{- with .Values.tolerations }}
   tolerations:
   {{- toYaml . | nindent 8 }}
   {{- end }}
  
  ---
  # templates/configmap.yaml
  apiVersion: v1
  kind: ConfigMap
  metadata:
   name: {{ include "web-app.fullname" . }}-config
   labels:
   {{- include "web-app.labels" . | nindent 4 }}
  data:
   app.properties: |
   server.port={{ .Values.service.targetPort }}
   logging.level=INFO
   database.pool.size=10
   cache.ttl=3600
  
  ---
  # templates/hpa.yaml
  {{- if .Values.autoscaling.enabled }}
  apiVersion: autoscaling/v2
  kind: HorizontalPodAutoscaler
  metadata:
   name: {{ include "web-app.fullname" . }}
   labels:
   {{- include "web-app.labels" . | nindent 4 }}
  spec:
   scaleTargetRef:
   apiVersion: apps/v1
   kind: Deployment
   name: {{ include "web-app.fullname" . }}
   minReplicas: {{ .Values.autoscaling.minReplicas }}
   maxReplicas: {{ .Values.autoscaling.maxReplicas }}
   metrics:
   {{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
   - type: Resource
   resource:
   name: cpu
   target:
   type: Utilization
   averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
   {{- end }}
   {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
   - type: Resource
   resource:
   name: memory
   target:
   type: Utilization
   averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
   {{- end }}
  {{- end }}
  ```
  
  This Helm chart includes:
  - Chart dependencies for PostgreSQL and Redis
  - Configurable values with sensible defaults
  - Security contexts and resource limits
  - Init containers for database readiness
  - Horizontal Pod Autoscaler
  - Ingress with TLS support
  - Health checks and probes