Charts و values.yaml
الهدف من الدرس
Section titled “الهدف من الدرس”ستتعلم بنية Helm chart، كيف تستخدم values.yaml، وكيف تنفذ install و upgrade و rollback بطريقة عملية.
الفكرة ببساطة
Section titled “الفكرة ببساطة”Helm لا يستبدل Kubernetes. Helm يضيف templating و packaging فوق YAML حتى لا تكرر نفس manifests لكل بيئة.
بنية Chart
Section titled “بنية Chart”web-chart/ Chart.yaml values.yaml templates/ deployment.yaml service.yamlChart.yaml
Section titled “Chart.yaml”apiVersion: v2name: web-chartdescription: Simple Nginx chart for the Arabic Kubernetes coursetype: applicationversion: 0.1.0appVersion: "1.27"values.yaml
Section titled “values.yaml”replicaCount: 2
image: repository: nginx tag: "1.27"
service: type: ClusterIP port: 80
resources: requests: cpu: "100m" memory: "128Mi" limits: cpu: "500m" memory: "256Mi"templates/deployment.yaml
Section titled “templates/deployment.yaml”apiVersion: apps/v1kind: Deploymentmetadata: name: {{ .Release.Name }}-web labels: app.kubernetes.io/name: web app.kubernetes.io/instance: {{ .Release.Name }}spec: replicas: {{ .Values.replicaCount }} selector: matchLabels: app.kubernetes.io/name: web app.kubernetes.io/instance: {{ .Release.Name }} template: metadata: labels: app.kubernetes.io/name: web app.kubernetes.io/instance: {{ .Release.Name }} spec: containers: - name: web image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" ports: - name: http containerPort: 80 readinessProbe: httpGet: path: / port: http resources: {{- toYaml .Values.resources | nindent 12 }}templates/service.yaml
Section titled “templates/service.yaml”apiVersion: v1kind: Servicemetadata: name: {{ .Release.Name }}-web labels: app.kubernetes.io/name: web app.kubernetes.io/instance: {{ .Release.Name }}spec: type: {{ .Values.service.type }} selector: app.kubernetes.io/name: web app.kubernetes.io/instance: {{ .Release.Name }} ports: - name: http port: {{ .Values.service.port }} targetPort: httpأوامر Helm
Section titled “أوامر Helm”helm lint ./web-charthelm template demo ./web-charthelm install demo ./web-charthelm upgrade demo ./web-chart --set image.tag=1.28helm history demohelm rollback demo 1helm uninstall demoExpected output:
==> Linting ./web-chart1 chart(s) linted, 0 chart(s) failed
NAME: demoSTATUS: deployedREVISION: 1ملفات values لكل بيئة
Section titled “ملفات values لكل بيئة”values-prod.yaml:
replicaCount: 3image: tag: "1.27"resources: requests: cpu: "200m" memory: "256Mi" limits: cpu: "1" memory: "512Mi"تطبيقها:
helm upgrade --install web-prod ./web-chart -f values-prod.yamlأخطاء شائعة
Section titled “أخطاء شائعة”| المشكلة | التشخيص | الحل |
|---|---|---|
| template لا يرندر | helm template | راجع الأقواس والمسافات |
| resources غير صحيحة | helm lint و helm template | استخدم toYaml و nindent |
| upgrade كسر التطبيق | helm history | نفذ helm rollback |
| values كثيرة ومربكة | مراجعة chart | قسم values حسب domain ولا تبالغ في templating |
Lab: إنشاء Helm chart لتطبيق Nginx
الهدف: بناء chart بسيط، رندر manifests، تنفيذ upgrade، ثم rollback.
Prerequisites
Section titled “Prerequisites”- Helm مثبت.
- Cluster محلي يعمل.
- أنشئ chart:
helm create web-chart- استبدل الملفات بالمحتوى الموجود في الدرس.
- افحص chart:
helm lint ./web-charthelm template demo ./web-chart- ثبته:
helm install demo ./web-chartkubectl get deploy,svc -l app.kubernetes.io/instance=demo- نفذ upgrade:
helm upgrade demo ./web-chart --set image.tag=1.28helm history demo- نفذ rollback:
helm rollback demo 1Expected output
Section titled “Expected output”REVISION UPDATED STATUS CHART APP VERSION1 Fri May 8 10:00:00 2026 superseded web-chart-0.1.0 1.272 Fri May 8 10:05:00 2026 deployed web-chart-0.1.0 1.27Cleanup
Section titled “Cleanup”helm uninstall demoالربط بالمشروع النهائي
Section titled “الربط بالمشروع النهائي”Project 5 سيحول مشروع full-stack إلى Helm chart. في Project 6 سيستهلك Argo CD هذا chart من Git.