متقدم
البحث فيأدلة «كيف»
طريقة البحث
  • اكتب المهمة بكلماتك (find port، open firewall، disk full) أو الصق رسالة الخطأ بين علامتي تنصيص.
  • اختر «الإجابة السريعة» لترى الأوامر فقط، أو مجالًا لتبقى في مجال واحد.
  • "كلمتان" تجد العبارة بالضبط.
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث
جرّب:

كيف 139CI/CD · GitOps

How to deploy an app with Argo CD from Git

With GitOps, Git is the truth: you change a YAML file, merge the pull request, and Argo CD makes the cluster match — and puts it back if someone changes it by hand. No kubectl apply from laptops, every change reviewed and in history, rollback = git revert. This how-to connects a repository, creates an Application, turns on auto-sync with self-heal, and shows the daily commands.

  • 5 الدروس
  • 6 الأوامر

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

$ مستخدم عادي# بصلاحية root (أو مع sudo)

139.1

The quick answer

apps/shop.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: shop
  namespace: argocd
spec:
  project: default
  source:
    repoURL: git@github.com:ORG/deploy.git
    targetRevision: main
    path: shop/overlays/prod
  destination:
    server: https://kubernetes.default.svc
    namespace: shop
  syncPolicy:
    automated:
      prune: true
      selfHeal: true
    syncOptions:
      - CreateNamespace=true
kubectl apply -f apps/shop.yaml
argocd app get shop
argocd app wait shop --health --timeout 300

139.2

Step by step

  1. A deploy repository with the manifests (plain YAML, Kustomize or a Helm chart with values) — separate from the app's source code is common:
deploy repo layout
shop/
  base/            deployment.yaml, service.yaml, kustomization.yaml
  overlays/
    staging/       kustomization.yaml (image tag, replicas)
    prod/          kustomization.yaml
apps/
  shop.yaml        the Argo CD Application
  1. Give Argo CD read access — a read-only deploy key:
ssh-keygen -t ed25519 -f ~/.ssh/argocd-deploy -N '' -C argocd
argocd repo add git@github.com:ORG/deploy.git --ssh-private-key-path ~/.ssh/argocd-deploy

Add the public key in the Git host as a read-only deploy key.

  1. Create the Application (quick answer). automated = sync on every Git change; prune = delete objects removed from Git; selfHeal = undo manual changes in the cluster.
  2. Deploy a new version — change Git, not the cluster:
cd deploy/shop/overlays/prod
kustomize edit set image registry.example.com/shop/api:1.4.3
git commit -am "shop api 1.4.3" && git push

Argo CD sees the commit (polling about every 3 minutes, or at once with a webhook) and rolls it out. CI can open this commit as a pull request automatically.

  1. Watch and act:
argocd app list
argocd app diff shop
argocd app sync shop
argocd app history shop
  1. Rollback = revert in Git (with auto-sync, an argocd app rollback is undone by the next sync):
git revert HEAD && git push
  1. Safety: use AppProjects to limit which repos and namespaces a team may deploy to, SSO for the UI, and keep Secrets out of Git (SOPS / External Secrets).

139.3

Check that it worked

argocd app get shop shows Sync Status: Synced and Health Status: Healthy; change a replica count by hand with kubectl scale — with self-heal, Argo CD sets it back within moments.

139.4

Common problems

ProblemCauseFix
OutOfSync that never endsFields changed by controllers (HPA replicas, defaults).ignoreDifferences for those fields; let the HPA own replicas.
ComparisonError: repository not accessibleDeploy key / URL wrong.argocd repo list; check the key and the repo URL.
Manual fix in the cluster disappearsselfHeal: true (by design).Change Git instead.
Deleted file, object still in the clusterprune is off.Turn on prune, or sync with prune once.
New version not deployedGit not updated, or polling delay.Check the commit; add a Git webhook for instant syncs.
Secrets visible in the UI diffPlain Secrets in Git or in manifests.SOPS or External Secrets; RBAC on who can see the app.

الأوامر في هذا الدرس

139.5

Go further

1In GitOps, how do you roll back a bad release?

Revert the commit in Git; Argo CD syncs the cluster back.

2What do prune and selfHeal do?

prune deletes objects removed from Git; selfHeal undoes manual changes in the cluster.

كل الأوامر في هذا الفصل