← Về danh sách bài học
Bài 20/25
🔄 Bài 20: GitOps với ArgoCD
🎯 Sau bài học này, bạn sẽ:
- Hiểu GitOps là gì
- Cài đặt ArgoCD
- Tạo Application từ Git repository
1. GitOps Là Gì?
GitOps = Infrastructure as Code + Git as single source of truth + Pull-based deployment
💡 Nguyên tắc:
• Declarative: Mọi thứ trong Git
• Versioned: Git history
• Automated: Sync tự động
• Auditable: AI commit là một thay đổi
• Declarative: Mọi thứ trong Git
• Versioned: Git history
• Automated: Sync tự động
• Auditable: AI commit là một thay đổi
2. Cài Đặt ArgoCD
# Install ArgoCD
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
# Chờ pods ready
kubectl get pods -n argocd
# Expose UI
kubectl port-forward svc/argocd-server -n argocd 8080:443
# Get admin password
kubectl -n argocd get secret argocd-initial-admin-secret \
-o jsonpath="{.data.password}" | base64 -d
3. Tạo Application
# application.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: my-app
namespace: argocd
spec:
project: default
source:
repoURL: https://github.com/user/k8s-manifests.git
targetRevision: main
path: apps/my-app
destination:
server: https://kubernetes.default.svc
namespace: production
syncPolicy:
automated:
prune: true # Xóa resources không còn trong Git
selfHeal: true # Tự sửa nếu ai đó thay đổi
4. ArgoCD CLI
# Install CLI
brew install argocd
# Login
argocd login localhost:8080
# Sync app
argocd app sync my-app
# Get status
argocd app get my-app
# Rollback
argocd app rollback my-app
📝 Tóm Tắt
- GitOps: Git as source of truth
- ArgoCD: GitOps controller cho K8s
- Application: Kết nối Git repo với cluster
- Sync: Tự động hoặc manual