GitOps & Deployment Strategies
ArgoCD for Model Deployment
English Content
What is ArgoCD?
ArgoCD is a declarative, GitOps continuous delivery tool for Kubernetes. It continuously monitors Git repositories and automatically applies changes to your cluster, ensuring your deployed applications match the desired state in Git.
Key features for ML:
- Declarative model deployment
- Automatic sync and self-healing
- Rollback with Git history
- Multi-cluster support
- Web UI for visibility
Installing ArgoCD
# Create namespace
kubectl create namespace argocd
# Install ArgoCD
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
# Access the UI (port forward)
kubectl port-forward svc/argocd-server -n argocd 8080:443
# Get initial admin password
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d
# Login with CLI
argocd login localhost:8080
Creating an Application
Define an ArgoCD Application for your model:
# apps/model-server-app.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: model-server
namespace: argocd
finalizers:
- resources-finalizer.argocd.argoproj.io
spec:
project: default
source:
repoURL: https://github.com/myorg/ml-deployments.git
targetRevision: main
path: overlays/production
destination:
server: https://kubernetes.default.svc
namespace: ml-production
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true
# Health checks for ML workloads
ignoreDifferences:
- group: apps
kind: Deployment
jsonPointers:
- /spec/replicas # Ignore HPA-managed replicas
Sync Strategies
Manual Sync: Review before applying
syncPolicy: {} # No automated sync
Automated Sync: Apply changes automatically
syncPolicy:
automated:
prune: true # Delete removed resources
selfHeal: true # Revert manual changes
allowEmpty: false
Sync with Waves: Control deployment order
# In your Kubernetes manifests
metadata:
annotations:
argocd.argoproj.io/sync-wave: "1" # Deploy order
Multi-Environment Setup
# apps/staging.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: model-server-staging
namespace: argocd
spec:
source:
repoURL: https://github.com/myorg/ml-deployments.git
targetRevision: main
path: overlays/staging
destination:
server: https://kubernetes.default.svc
namespace: ml-staging
syncPolicy:
automated:
selfHeal: true
prune: true
# apps/production.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: model-server-production
namespace: argocd
spec:
source:
repoURL: https://github.com/myorg/ml-deployments.git
targetRevision: main
path: overlays/production
destination:
server: https://kubernetes.default.svc
namespace: ml-production
syncPolicy:
automated:
selfHeal: true
prune: true
ApplicationSet for Multiple Models
Deploy multiple models with a single template:
# apps/model-appset.yaml
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: ml-models
namespace: argocd
spec:
generators:
- list:
elements:
- model: sentiment-classifier
version: v1.2.0
replicas: "3"
- model: fraud-detector
version: v2.1.0
replicas: "5"
- model: recommendation-engine
version: v1.0.0
replicas: "2"
template:
metadata:
name: '{{model}}'
spec:
project: default
source:
repoURL: https://github.com/myorg/ml-deployments.git
targetRevision: main
path: models/{{model}}
helm:
parameters:
- name: image.tag
value: '{{version}}'
- name: replicas
value: '{{replicas}}'
destination:
server: https://kubernetes.default.svc
namespace: ml-production
syncPolicy:
automated:
selfHeal: true
Health Checks for ML Services
# Custom health check for model server
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-cm
namespace: argocd
data:
resource.customizations.health.argoproj.io_Application: |
hs = {}
hs.status = "Progressing"
hs.message = ""
if obj.status ~= nil then
if obj.status.health ~= nil then
hs.status = obj.status.health.status
if obj.status.health.message ~= nil then
hs.message = obj.status.health.message
end
end
end
return hs
Rollback Procedure
# View application history
argocd app history model-server
# Rollback to specific revision
argocd app rollback model-server 5
# Or via Git
git revert HEAD
git push origin main
# ArgoCD automatically syncs to reverted state
Key Takeaways
| ArgoCD Feature | ML Use Case |
|---|---|
| Application CRD | Define model deployment |
| Automated sync | Deploy on Git changes |
| Self-heal | Prevent configuration drift |
| ApplicationSet | Multi-model deployments |
| Sync waves | Control deployment order |
المحتوى العربي
ما هو ArgoCD؟
ArgoCD هو أداة تسليم مستمر تصريحية GitOps لـ Kubernetes. يراقب باستمرار مستودعات Git ويطبق التغييرات تلقائياً على الكلستر الخاص بك، مما يضمن تطابق تطبيقاتك المنشورة مع الحالة المطلوبة في Git.
الميزات الرئيسية لـ ML:
- نشر النماذج التصريحي
- المزامنة التلقائية والشفاء الذاتي
- التراجع مع تاريخ Git
- دعم الكلسترات المتعددة
- واجهة ويب للرؤية
تثبيت ArgoCD
# إنشاء namespace
kubectl create namespace argocd
# تثبيت ArgoCD
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
# الوصول إلى الواجهة (تحويل المنفذ)
kubectl port-forward svc/argocd-server -n argocd 8080:443
# الحصول على كلمة مرور المشرف الأولية
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d
# تسجيل الدخول مع CLI
argocd login localhost:8080
إنشاء تطبيق
عرّف تطبيق ArgoCD لنموذجك:
# apps/model-server-app.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: model-server
namespace: argocd
finalizers:
- resources-finalizer.argocd.argoproj.io
spec:
project: default
source:
repoURL: https://github.com/myorg/ml-deployments.git
targetRevision: main
path: overlays/production
destination:
server: https://kubernetes.default.svc
namespace: ml-production
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true
# فحوصات الصحة لأحمال عمل ML
ignoreDifferences:
- group: apps
kind: Deployment
jsonPointers:
- /spec/replicas # تجاهل replicas المُدارة بـ HPA
استراتيجيات المزامنة
المزامنة اليدوية: المراجعة قبل التطبيق
syncPolicy: {} # لا مزامنة آلية
المزامنة الآلية: تطبيق التغييرات تلقائياً
syncPolicy:
automated:
prune: true # حذف الموارد المُزالة
selfHeal: true # التراجع عن التغييرات اليدوية
allowEmpty: false
المزامنة مع Waves: التحكم في ترتيب النشر
# في manifests Kubernetes الخاصة بك
metadata:
annotations:
argocd.argoproj.io/sync-wave: "1" # ترتيب النشر
إعداد بيئات متعددة
# apps/staging.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: model-server-staging
namespace: argocd
spec:
source:
repoURL: https://github.com/myorg/ml-deployments.git
targetRevision: main
path: overlays/staging
destination:
server: https://kubernetes.default.svc
namespace: ml-staging
syncPolicy:
automated:
selfHeal: true
prune: true
# apps/production.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: model-server-production
namespace: argocd
spec:
source:
repoURL: https://github.com/myorg/ml-deployments.git
targetRevision: main
path: overlays/production
destination:
server: https://kubernetes.default.svc
namespace: ml-production
syncPolicy:
automated:
selfHeal: true
prune: true
ApplicationSet لنماذج متعددة
انشر نماذج متعددة بقالب واحد:
# apps/model-appset.yaml
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: ml-models
namespace: argocd
spec:
generators:
- list:
elements:
- model: sentiment-classifier
version: v1.2.0
replicas: "3"
- model: fraud-detector
version: v2.1.0
replicas: "5"
- model: recommendation-engine
version: v1.0.0
replicas: "2"
template:
metadata:
name: '{{model}}'
spec:
project: default
source:
repoURL: https://github.com/myorg/ml-deployments.git
targetRevision: main
path: models/{{model}}
helm:
parameters:
- name: image.tag
value: '{{version}}'
- name: replicas
value: '{{replicas}}'
destination:
server: https://kubernetes.default.svc
namespace: ml-production
syncPolicy:
automated:
selfHeal: true
فحوصات الصحة لخدمات ML
# فحص صحة مخصص لخادم النموذج
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-cm
namespace: argocd
data:
resource.customizations.health.argoproj.io_Application: |
hs = {}
hs.status = "Progressing"
hs.message = ""
if obj.status ~= nil then
if obj.status.health ~= nil then
hs.status = obj.status.health.status
if obj.status.health.message ~= nil then
hs.message = obj.status.health.message
end
end
end
return hs
إجراء التراجع
# عرض تاريخ التطبيق
argocd app history model-server
# التراجع إلى revision محدد
argocd app rollback model-server 5
# أو عبر Git
git revert HEAD
git push origin main
# ArgoCD يزامن تلقائياً إلى الحالة المُرجعة
النقاط الرئيسية
| ميزة ArgoCD | حالة استخدام ML |
|---|---|
| Application CRD | تعريف نشر النموذج |
| المزامنة الآلية | النشر عند تغييرات Git |
| الشفاء الذاتي | منع انجراف التكوين |
| ApplicationSet | نشر نماذج متعددة |
| Sync waves | التحكم في ترتيب النشر |