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.
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...
