GitOps-workflow inrichten met ArgoCD
Automatisch deployen vanuit uw Git-repository naar uw Proxy Kubernetes-cluster.
Met GitOps wordt uw Git-repository de single source of truth voor uw infrastructuur. Geschatte leestijd: 18 minuten.
Wat is GitOps?
GitOps is een operationeel model waarbij:
- De gewenste staat van uw cluster in Git staat
- ArgoCD continu synchroniseert tussen Git en uw cluster
- Elke wijziging traceerbaar is via Git history
- Rollbacks simpelweg een
git revertzijn
Vereisten
- Een draaiend Proxy Platform cluster (handleiding)
- ArgoCD geïnstalleerd op uw cluster (zie stap 1)
- Een Git-repository met uw Kubernetes manifests
Stap 1: ArgoCD installeren
Installeer ArgoCD op uw cluster
ArgoCD wordt niet standaard meegeleverd; installeer het zelf:
Applicaties zoals ArgoCD komen op termijn beschikbaar via de Marketplace in het controlepaneel voor installatie met een klik. Tot die tijd installeert u ze handmatig zoals hieronder.
kubectl create namespace argocd
kubectl apply -n argocd \
-f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yamlHet initiële admin-wachtwoord vindt u daarna met:
kubectl -n argocd get secret argocd-initial-admin-secret \
-o jsonpath="{.data.password}" | base64 -dCLI installeren
# macOS
brew install argocd
# Linux
curl -sSL -o argocd https://github.com/argoproj/argo-cd/releases/latest/download/argocd-linux-amd64
chmod +x argocd && sudo mv argocd /usr/local/bin/Inloggen via CLI
# Poort-forward de ArgoCD-server (of stel zelf een Ingress in)
kubectl -n argocd port-forward svc/argocd-server 8080:443
argocd login localhost:8080 \
--username admin \
--password <initial-password>Stap 2: Repository koppelen
argocd repo add https://gitlab.example.com/mijn-org/k8s-manifests.git \
--username deploy-token \
--password <token>Gebruik altijd een deploy token of SSH key in plaats van persoonlijke credentials voor repository-toegang.
Stap 3: Repository structuur
Organiseer uw repository met een duidelijke structuur:
k8s-manifests/
├── base/
│ ├── deployment.yaml
│ ├── service.yaml
│ ├── ingress.yaml
│ └── kustomization.yaml
├── overlays/
│ ├── staging/
│ │ ├── kustomization.yaml
│ │ └── replicas-patch.yaml
│ └── production/
│ ├── kustomization.yaml
│ ├── replicas-patch.yaml
│ └── resources-patch.yaml
└── argocd/
└── application.yamlStap 4: ArgoCD Application aanmaken
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: mijn-app-productie
namespace: argocd
spec:
project: default
source:
repoURL: https://gitlab.example.com/mijn-org/k8s-manifests.git
path: overlays/production
targetRevision: main
destination:
server: https://kubernetes.default.svc
namespace: mijn-app
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=truekubectl apply -f argocd/application.yamlStap 5: Workflow testen
Maak een wijziging
# Pas de replica count aan
cd overlays/production
cat > replicas-patch.yaml << 'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
name: mijn-app
spec:
replicas: 5
EOFPush naar Git
git add .
git commit -m "feat: scale to 5 replicas"
git push origin mainVerifieer synchronisatie
ArgoCD detecteert de wijziging binnen 3 minuten (of direct bij webhook):
argocd app get mijn-app-productieWebhook configureren (optioneel)
Voor directe synchronisatie bij elke push:
https://<uw-argocd-adres>/api/webhookConfigureer de webhook in GitLab via Settings → Webhooks met de events: Push en Tag push.
Volgende stappen
- Cluster architectuur — Begrijp de onderliggende infrastructuur
- API Referentie — Automatiseer met de Platform API