Cloud / HELM Interview Questions
How do you implement resource quotas and limit ranges with Helm?
Resource quotas and limit ranges enforce resource constraints at namespace level, critical for multi-tenant clusters.
Resource Quota template: # templates/resourcequota.yaml {{- if .Values.resourceQuota.enabled }} apiVersion: v1 kind: ResourceQuota metadata: name: {{ include "myapp.fullname" . }}-quota spec: hard: requests.cpu: {{ .Values.resourceQuota.requests.cpu }} requests.memory: {{ .Values.resourceQuota.requests.memory }} limits.cpu: {{ .Values.resourceQuota.limits.cpu }} limits.memory: {{ .Values.resourceQuota.limits.memory }} persistentvolumeclaims: {{ .Values.resourceQuota.pvcs | default "10" }} pods: {{ .Values.resourceQuota.pods | default "20" }} services: {{ .Values.resourceQuota.services | default "10" }} secrets: {{ .Values.resourceQuota.secrets | default "50" }} configmaps: {{ .Values.resourceQuota.configmaps | default "50" }} {{- end }}
Limit Range for default requests: # templates/limitrange.yaml {{- if .Values.limitRange.enabled }} apiVersion: v1 kind: LimitRange metadata: name: {{ include "myapp.fullname" . }}-limits spec: limits: - type: Container default: cpu: {{ .Values.limitRange.default.cpu }} memory: {{ .Values.limitRange.default.memory }} defaultRequest: cpu: {{ .Values.limitRange.defaultRequest.cpu }} memory: {{ .Values.limitRange.defaultRequest.memory }} max: cpu: {{ .Values.limitRange.max.cpu }} memory: {{ .Values.limitRange.max.memory }} min: cpu: {{ .Values.limitRange.min.cpu }} memory: {{ .Values.limitRange.min.memory }} - type: Pod max: cpu: {{ .Values.limitRange.podMax.cpu }} memory: {{ .Values.limitRange.podMax.memory }} {{- end }}
Per-namespace quotas with values: # environments/dev/values.yaml resourceQuota: enabled: true requests: cpu: "2" memory: "4Gi" limits: cpu: "4" memory: "8Gi" pods: 10 # environments/prod/values.yaml resourceQuota: enabled: true requests: cpu: "10" memory: "20Gi" limits: cpu: "20" memory: "40Gi" pods: 50
Template validation with quota: # Check if quota allows new resources {{- $currentPods := lookup "v1" "Pod" .Release.Namespace "" | len -}} {{- $quotaPods := .Values.resourceQuota.pods | int -}} {{- if ge $currentPods $quotaPods }} {{- fail "Pod quota would be exceeded" -}} {{- end }}
Monitoring quota usage: # Get quota status kubectl get resourcequota -n mynamespace # Watch quota during deployment kubectl get resourcequota myapp-quota -n mynamespace -w # Alert on quota near limits (Prometheus) kubectl resourcequota used > 80%
Multi-tenant quota strategy: # Shared quota for teams team-a-quota: hard: pods: "50" requests.cpu: "10" requests.memory: 20Gi # Per-application quotas within team app-quota: hard: pods: "10" requests.cpu: "2"
Best practices: Always set LimitRange to provide default resource requests, set ResourceQuota high enough for rolling updates (2x peak usage), test quota exhaustion scenarios, and monitor quota usage with dashboards.
More Related questions...