# راهنمای Deployment روی Kubernetes با Helm این راهنما نحوه deploy کردن پلتفرم Peikarband روی Kubernetes با استفاده از Helm Chart را توضیح می‌دهد. ## پیش‌نیازها ### 1. ابزارهای مورد نیاز ```bash # Kubectl (v1.24+) kubectl version --client # Helm (v3.10+) helm version # Docker (برای build local) docker --version ``` ### 2. دسترسی به Kubernetes Cluster ```bash # تست دسترسی kubectl cluster-info kubectl get nodes ``` ### 3. Namespace ها ```bash # ساخت namespace ها kubectl create namespace production kubectl create namespace staging ``` ## ساختار Helm Chart ``` helm/peikarband/ ├── Chart.yaml # Metadata ├── values.yaml # Default values ├── values-production.yaml # Production overrides ├── templates/ │ ├── _helpers.tpl # Helper templates │ ├── deployment.yaml # Deployment │ ├── service.yaml # Service │ ├── ingress.yaml # Ingress │ ├── configmap.yaml # ConfigMap │ ├── serviceaccount.yaml │ ├── hpa.yaml # Horizontal Pod Autoscaler │ ├── pdb.yaml # Pod Disruption Budget │ ├── networkpolicy.yaml │ └── NOTES.txt └── .helmignore ``` ## مراحل Deployment ### 1. آماده‌سازی Secrets ابتدا باید secrets مورد نیاز را ایجاد کنید: ```bash # Database credentials kubectl create secret generic peikarband-secrets \ --from-literal=db-username=peikarband \ --from-literal=db-password=STRONG_PASSWORD_HERE \ --from-literal=redis-password=REDIS_PASSWORD_HERE \ -n production # برای staging kubectl create secret generic peikarband-secrets \ --from-literal=db-username=peikarband \ --from-literal=db-password=STAGING_PASSWORD \ --from-literal=redis-password=REDIS_PASSWORD \ -n staging ``` ### 2. Build و Push Docker Image #### روش اول: با GitHub Actions (توصیه می‌شود) ```bash # فقط یک tag بزنید و GitHub Actions خودکار build و deploy می‌کند git tag -a v0.1.0 -m "Release v0.1.0" git push origin v0.1.0 ``` #### روش دوم: Build دستی ```bash # Build image docker build -t peikarband/landing:0.1.0 . # Tag for registry docker tag peikarband/landing:0.1.0 registry.example.com/peikarband/landing:0.1.0 # Push docker push registry.example.com/peikarband/landing:0.1.0 ``` ### 3. Validate Helm Chart قبل از deploy، chart را validate کنید: ```bash # Lint helm lint helm/peikarband # Dry-run helm install peikarband-test ./helm/peikarband \ --dry-run \ --debug \ --namespace production # Template rendering helm template peikarband ./helm/peikarband > rendered.yaml ``` ### 4. Deploy به Staging ```bash helm upgrade --install peikarband-staging ./helm/peikarband \ --namespace staging \ --create-namespace \ --set image.repository=registry.example.com/peikarband/landing \ --set image.tag=0.1.0 \ --set ingress.hosts[0].host=staging.peikarband.ir \ --set replicaCount=2 \ --wait \ --timeout 5m ``` ### 5. تست Staging ```bash # چک کردن pods kubectl get pods -n staging # چک کردن logs kubectl logs -f deployment/peikarband-staging -n staging # Port forward برای تست local kubectl port-forward svc/peikarband-staging 3000:3000 -n staging # تست health check curl http://localhost:8000/ping ``` ### 6. Deploy به Production ```bash helm upgrade --install peikarband-prod ./helm/peikarband \ --namespace production \ --create-namespace \ --set image.repository=registry.example.com/peikarband/landing \ --set image.tag=0.1.0 \ --values helm/peikarband/values-production.yaml \ --wait \ --timeout 10m ``` ## پیکربندی‌های مهم ### 1. تغییر تعداد Replicas ```bash # با Helm helm upgrade peikarband-prod ./helm/peikarband \ --namespace production \ --reuse-values \ --set replicaCount=5 # یا با kubectl kubectl scale deployment peikarband-prod --replicas=5 -n production ``` ### 2. Update Image Version ```bash helm upgrade peikarband-prod ./helm/peikarband \ --namespace production \ --reuse-values \ --set image.tag=0.2.0 ``` ### 3. تغییر Resources ```bash helm upgrade peikarband-prod ./helm/peikarband \ --namespace production \ --reuse-values \ --set resources.limits.cpu=2000m \ --set resources.limits.memory=2Gi ``` ### 4. فعال/غیرفعال کردن Autoscaling ```bash # فعال کردن helm upgrade peikarband-prod ./helm/peikarband \ --namespace production \ --reuse-values \ --set autoscaling.enabled=true \ --set autoscaling.minReplicas=3 \ --set autoscaling.maxReplicas=10 # غیرفعال کردن helm upgrade peikarband-prod ./helm/peikarband \ --namespace production \ --reuse-values \ --set autoscaling.enabled=false \ --set replicaCount=3 ``` ## Ingress و SSL/TLS ### نصب cert-manager (برای Let's Encrypt) ```bash # نصب cert-manager kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.13.0/cert-manager.yaml # ساخت ClusterIssuer cat <