Cloud / HELM Interview Questions
How do you manage Helm charts for stateful applications (databases, Kafka)?
Stateful applications require special handling for persistent storage, ordering, and discovery.
StatefulSet configuration: # templates/statefulset.yaml apiVersion: apps/v1 kind: StatefulSet metadata: name: {{ include "myapp.fullname" . }} spec: serviceName: {{ include "myapp.fullname" . }}-headless replicas: {{ .Values.replicaCount }} podManagementPolicy: OrderedReady # or Parallel updateStrategy: type: RollingUpdate rollingUpdate: partition: 0 # For canary updates selector: matchLabels: {{- include "myapp.selectorLabels" . | nindent 6 }} template: metadata: labels: {{- include "myapp.selectorLabels" . | nindent 8 }} spec: containers: - name: app image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" volumeMounts: - name: data mountPath: /var/lib/app volumeClaimTemplates: - metadata: name: data spec: accessModes: [ "ReadWriteOnce" ] storageClassName: {{ .Values.persistence.storageClass }} resources: requests: storage: {{ .Values.persistence.size }}
Headless service for discovery: # templates/service-headless.yaml apiVersion: v1 kind: Service metadata: name: {{ include "myapp.fullname" . }}-headless spec: clusterIP: None selector: {{- include "myapp.selectorLabels" . | nindent 4 }} ports: - port: {{ .Values.service.port }} name: app
Pod identity script: # In container startup #!/bin/bash export POD_NAME=$(hostname) export POD_INDEX=${POD_NAME##*-} # For clustered apps (Kafka, ZooKeeper) if [ $POD_INDEX -eq 0 ]; then # This is the first pod /entrypoint.sh --bootstrap else # Wait for first pod until nslookup {{ include "myapp.fullname" . }}-0; do sleep 2; done /entrypoint.sh --join {{ include "myapp.fullname" . }}-0.$(POD_NAMESPACE).svc.cluster.local fi
Persistent Volume management: # Prevent PVC deletion with annotation annotations: "helm.sh/resource-policy": keep # values.yaml persistence: enabled: true size: 10Gi storageClass: fast existingClaim: "" # Conditional PVC {{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) }} apiVersion: v1 kind: PersistentVolumeClaim metadata: name: {{ include "myapp.fullname" . }}-data spec: accessModes: - ReadWriteOnce resources: requests: storage: {{ .Values.persistence.size }} {{- end }}
Ordered readiness probes: readinessProbe: exec: command: - sh - -c - | # For Cassandra nodetool status | grep "^UN" | grep $(hostname) initialDelaySeconds: 30 periodSeconds: 10
Backup and restore hooks: # Pre-upgrade backup hookannotations: "helm.sh/hook": pre-upgrade "helm.sh/hook-weight": "1" --- apiVersion: batch/v1 kind: Job metadata: name: {{ .Release.Name }}-backup spec: template: spec: containers: - name: backup image: bitnami/postgresql:latest command: - pg_dump - -h {{ .Release.Name }}-postgresql - -U postgres - mydb volumeMounts: - name: backup mountPath: /backup volumes: - name: backup persistentVolumeClaim: claimName: backup-pvc
More Related questions...