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

كيف 243CI/CD · GitOps

How to deploy from Git with Flux

With GitOps the cluster pulls its desired state from Git: no kubectl apply from laptops, no cluster credentials in CI, every change reviewed in a pull request and easy to roll back with git revert. Flux does this with a few controllers in the cluster. This how-to bootstraps Flux into a cluster from a GitHub repository, adds an app with a Kustomization, watches it reconcile, and handles a failed change.

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

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

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

243.1

The quick answer

export GITHUB_TOKEN=$(cat ~/.flux-bootstrap-token)
flux check --pre
flux bootstrap github --owner=example-org --repository=fleet --branch=main --path=clusters/prod --personal=false
flux get kustomizations

243.2

Step by step

  1. Pre-check (line 2) — Kubernetes version and access are fine.
  2. Bootstrap (line 3) — Flux creates (or uses) the repo fleet, commits its own manifests to clusters/prod/flux-system, installs itself and from now on syncs that path. The token needs repo admin rights only for bootstrap; Flux then uses a deploy key.
  3. Add an app — the app's manifests (or a Kustomize overlay) in apps/shop/prod/, and a Flux Kustomization that points to it:
clusters/prod/shop.yaml
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
  name: shop
  namespace: flux-system
spec:
  interval: 5m
  path: ./apps/shop/prod
  prune: true
  wait: true
  timeout: 3m
  sourceRef:
    kind: GitRepository
    name: flux-system
  targetNamespace: shop

prune: true deletes objects you remove from Git; wait: true marks it ready only when the workloads are healthy.

  1. Commit and push — Flux applies it within the interval. Faster: flux reconcile kustomization shop --with-source.
  2. Watch — flux get kustomizations shows READY True and the applied revision; flux events --for Kustomization/shop and flux logs show why something fails.
  3. A failed change — Flux keeps the last good state running and shows the error. Fix it with a new commit or git revert — never with kubectl edit (Flux would undo it at the next reconcile).
  4. Helm charts — HelmRepository + HelmRelease objects; values in Git.
  5. Secrets — never plain in Git: SOPS decryption in the Kustomization, or the External Secrets Operator.

243.3

Check that it worked

flux check reports all controllers healthy; flux get kustomizations shows flux-system and shop with READY True and the latest commit; kubectl -n shop get deploy shows the app; a commit that changes the replica count is applied within minutes without anyone running kubectl.

243.4

Common problems

ProblemCauseFix
Bootstrap fails with 403Token missing rights or org restrictions.Token with repo admin for bootstrap; org allows it.
kustomization path not foundWrong path in the Kustomization.Path relative to the repo root, starting with ./.
Manual change undoneFlux reconciles Git state.Change Git, not the cluster.
READY False with health check timeoutPods do not become ready.kubectl describe the pods; fix image/probes; raise timeout.
Deleted file but object still thereprune: false.Enable prune (carefully).
Secret decryption failedSOPS key secret missing.Create the sops-age secret; decryption block.

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

243.5

Go further

1Why should you not fix a Flux-managed object with kubectl edit?

Flux reapplies the state from Git at the next reconcile, so the manual change is undone; change Git instead.

2What does prune: true do in a Flux Kustomization?

Objects removed from Git are also deleted from the cluster.

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