- Move Docker files to build/docker/ - Move CI/CD configs to build/ci/ - Move deployment configs to deploy/ (helm, k8s, argocd) - Move config files to config/ - Move scripts to tools/ - Consolidate assets to assets/ (Reflex compatible) - Add data/ directory for local data (gitignored) - Update all path references in Makefile, Dockerfile, CI configs - Add comprehensive README files for build/ and deploy/ - Update project documentation Benefits: - Clear separation of concerns - Cleaner root directory - Better developer experience - Enterprise-grade structure - Improved maintainability
227 lines
4.7 KiB
Markdown
227 lines
4.7 KiB
Markdown
# Deploy Directory
|
|
|
|
این دایرکتوری شامل همه فایلهای مربوط به **deployment** پروژه است.
|
|
|
|
## 📁 ساختار
|
|
|
|
```
|
|
deploy/
|
|
├── helm/ # Helm charts
|
|
│ └── peikarband/
|
|
│ ├── Chart.yaml # Chart metadata
|
|
│ ├── values.yaml # Default values
|
|
│ ├── values-production.yaml
|
|
│ ├── values-staging.yaml
|
|
│ └── templates/ # K8s resource templates
|
|
├── kubernetes/ # Raw K8s manifests
|
|
│ └── secrets-template.yaml
|
|
└── argocd/ # ArgoCD GitOps
|
|
├── application.yaml
|
|
├── application-staging.yaml
|
|
└── README.md
|
|
```
|
|
|
|
## ⚓ Helm Charts
|
|
|
|
### نصب با Helm
|
|
|
|
**Staging:**
|
|
```bash
|
|
helm upgrade --install peikarband ./deploy/helm/peikarband \
|
|
--namespace staging \
|
|
--values deploy/helm/peikarband/values-staging.yaml \
|
|
--create-namespace
|
|
```
|
|
|
|
**Production:**
|
|
```bash
|
|
helm upgrade --install peikarband ./deploy/helm/peikarband \
|
|
--namespace production \
|
|
--values deploy/helm/peikarband/values-production.yaml \
|
|
--create-namespace
|
|
```
|
|
|
|
**یا استفاده از Makefile:**
|
|
```bash
|
|
make helm-upgrade NAMESPACE=production
|
|
```
|
|
|
|
### Values Files
|
|
|
|
- **`values.yaml`**: Default values (برای development)
|
|
- **`values-staging.yaml`**: Staging overrides
|
|
- **`values-production.yaml`**: Production overrides
|
|
|
|
**مهمترین تنظیمات:**
|
|
```yaml
|
|
image:
|
|
repository: hub.peikarband.ir/peikarband/landing
|
|
tag: "latest"
|
|
|
|
resources:
|
|
requests:
|
|
cpu: 500m
|
|
memory: 512Mi
|
|
limits:
|
|
cpu: 1000m
|
|
memory: 1Gi
|
|
|
|
autoscaling:
|
|
enabled: true
|
|
minReplicas: 2
|
|
maxReplicas: 10
|
|
```
|
|
|
|
## ☸️ Kubernetes Manifests
|
|
|
|
### Secrets
|
|
Template برای secrets:
|
|
```bash
|
|
kubectl create secret generic peikarband-secrets \
|
|
--from-file=deploy/kubernetes/secrets-template.yaml \
|
|
--namespace production
|
|
```
|
|
|
|
## 🔄 ArgoCD GitOps
|
|
|
|
### Setup ArgoCD Application
|
|
|
|
**Staging:**
|
|
```bash
|
|
kubectl apply -f deploy/argocd/application-staging.yaml
|
|
```
|
|
|
|
**Production:**
|
|
```bash
|
|
kubectl apply -f deploy/argocd/application.yaml
|
|
```
|
|
|
|
### Sync Policy
|
|
- **Auto-sync**: Enabled برای staging
|
|
- **Manual sync**: Required برای production
|
|
|
|
### مانیتورینگ
|
|
```bash
|
|
argocd app get peikarband
|
|
argocd app sync peikarband
|
|
argocd app logs peikarband
|
|
```
|
|
|
|
## 🎯 Deployment Flow
|
|
|
|
```mermaid
|
|
graph LR
|
|
A[Code Push] --> B[CI Build]
|
|
B --> C[Push Image]
|
|
C --> D{Environment}
|
|
D -->|Staging| E[ArgoCD Auto-Sync]
|
|
D -->|Production| F[Manual ArgoCD Sync]
|
|
E --> G[Deploy]
|
|
F --> G
|
|
```
|
|
|
|
### Staging Deployment
|
|
1. Push به branch `main`
|
|
2. CI builds & pushes image
|
|
3. ArgoCD auto-sync
|
|
4. Rolling update
|
|
|
|
### Production Deployment
|
|
1. Tag release (e.g., `v1.0.0`)
|
|
2. CI builds & pushes image با tag
|
|
3. Update `values-production.yaml` با tag جدید
|
|
4. Manual ArgoCD sync یا `make helm-upgrade`
|
|
5. Rolling update با health checks
|
|
|
|
## 🔍 Troubleshooting
|
|
|
|
### Check Pod Status
|
|
```bash
|
|
kubectl get pods -n production
|
|
kubectl logs -f deployment/peikarband -n production
|
|
kubectl describe pod <pod-name> -n production
|
|
```
|
|
|
|
### Check Helm Release
|
|
```bash
|
|
helm list -n production
|
|
helm status peikarband -n production
|
|
helm history peikarband -n production
|
|
```
|
|
|
|
### Rollback
|
|
```bash
|
|
helm rollback peikarband <revision> -n production
|
|
# یا
|
|
kubectl rollout undo deployment/peikarband -n production
|
|
```
|
|
|
|
## 📊 Monitoring & Observability
|
|
|
|
### Health Checks
|
|
- **Liveness**: `/ping` endpoint
|
|
- **Readiness**: `/health` endpoint
|
|
- **Startup**: 60s timeout
|
|
|
|
### Metrics
|
|
- Prometheus metrics exposed on `/metrics`
|
|
- Grafana dashboards
|
|
- Alert rules
|
|
|
|
### Logs
|
|
- Centralized logging with Loki
|
|
- Log aggregation
|
|
- Search & filtering
|
|
|
|
## 🔐 Security
|
|
|
|
### Secrets Management
|
|
- Kubernetes Secrets
|
|
- Sealed Secrets (recommended)
|
|
- External Secrets Operator
|
|
|
|
### Network Policies
|
|
- Ingress rules defined
|
|
- Egress restrictions
|
|
- Service mesh (optional)
|
|
|
|
### RBAC
|
|
- ServiceAccount per namespace
|
|
- Minimal permissions
|
|
- Pod Security Standards
|
|
|
|
## 🎯 Best Practices
|
|
|
|
1. **Versioning**
|
|
- Semantic versioning
|
|
- Tag images با versions
|
|
- Lock Helm chart versions
|
|
|
|
2. **Resources**
|
|
- Set requests & limits
|
|
- Monitor usage
|
|
- Right-size pods
|
|
|
|
3. **Autoscaling**
|
|
- HPA based on CPU/memory
|
|
- VPA for recommendations
|
|
- Cluster autoscaling
|
|
|
|
4. **High Availability**
|
|
- Multiple replicas (min 2)
|
|
- Pod disruption budgets
|
|
- Anti-affinity rules
|
|
|
|
5. **Updates**
|
|
- Rolling updates
|
|
- Health checks
|
|
- Gradual rollout
|
|
|
|
## 📚 مستندات بیشتر
|
|
|
|
- [Deployment Checklist](../docs/deployment/DEPLOYMENT_CHECKLIST.md)
|
|
- [Production Deployment Guide](../docs/deployment/PRODUCTION_DEPLOYMENT.md)
|
|
- [Quick Start](../docs/deployment/DEPLOYMENT_QUICK_START.md)
|
|
- [Kubernetes Guide](../docs/deployment/kubernetes.md)
|
|
|