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
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
