Flux CD Agent Skills

repository·main·Indexed 41 days ago

https://github.com/fluxcd/agent-skills

A collection of reusable AI skills providing expertise in Flux CD, Kubernetes, and GitOps best practices. Includes the gitops-knowledge skill for manifest generation, gitops-repo-audit for repository security and structure validation, and gitops-cluster-debug for troubleshooting live clusters via the flux-operator-mcp server. Compatible with Claude Code, Codex, GitHub Copilot, and the Flux CLI.

Tokens
92.2K
Snippets
163
Records
312
Agent score
53%

What's inside Flux CD Agent Skills

  1. Flux Kustomization Reference

    main

    A Flux Kustomization (apiVersion: kustomize.toolkit.fluxcd.io/v1) is the primary mechanism for deploying manifests to a cluster by building and applying Kustomize overlays or plain Kubernetes YAML from a source artifact.

    Note: This is the Flux Kustomization CRD, which is distinct from a standard Kustomize kustomization.yaml file.

    apiVersion: kustomize.toolkit.fluxcd.io/v1
    kind: Kustomization
    metadata:
      name: my-app
      namespace: flux-system
    spec:
      interval: 10m
      retryInterval: 2m
      sourceRef:
        kind: GitRepository
        name: my-app
      path: ./deploy/production
      prune: true
      wait: true
      timeout: 5m
      targetNamespace: my-app
      serviceAccountName: flux
      postBuild:
        substituteFrom:
          - kind: ConfigMap
            name: flux-runtime-info
  2. Use the Flux Controller Patch Releases skill

    main

    The flux-controller-patch-releases skill is designed to automate the upstream Flux controller patch release procedure. It is specifically for preparing new controller patch releases from a release series branch, drafting changelog entries, tagging releases, and opening follow-up changelog PRs back to main.

    Supported controllers:

    • helm-controller
    • image-automation-controller
    • image-reflector-controller
    • kustomize-controller
    • notification-controller
    • source-controller
    • source-watcher

    Important Restrictions:

    • Use this skill only for the controllers listed above. Do not use it for flux2, pkg, or other non-controller repositories.
    • Every git commit must use the -s (sign-off) flag.
    • Do not include Co-Authored-By lines, your own name, or AI attribution in commit messages, PR titles, or PR descriptions.
  3. Run a GitOps repository audit with gitops-repo-audit

    main

    The gitops-repo-audit skill allows you to audit and validate Flux CD GitOps repositories by scanning local files. It performs Kubernetes schema validation, detects deprecated Flux APIs, reviews security posture (RBAC, secrets, multi-tenancy), and generates a prioritized report.

    Prerequisites:

    • flux CLI
    • flux-schema CLI
    • kustomize or kubectl installed

    Usage Scenarios:

    • Use when you need to audit, analyze, validate, review, or security-check a GitOps repository.
    • You can perform targeted audits (e.g., "are my HelmReleases configured correctly?") or broad audits ("audit this repo").
  4. What is Gitless Image Automation and when to use it

    main

    Gitless image automation updates running workloads (like HelmRelease or Kustomization) when new container images or Helm chart versions are published, without committing tag bumps back to Git. It uses Flux Operator's ResourceSetInputProvider to scan registries and re-renders the owning ResourceSet directly.

    Comparison: Git-based vs. Gitless

    ConcernGit-basedGitless
    Audit trailGit commitsFlux events / notifications
    Approval workflowYes (via PRs)No
    Write accessRequires bot with Git write accessNo Git access required
    Controllersimage-automation-controller + image-reflector-controllerflux-operator + helm/kustomize controllers

    Use Git-based automation if you require a PR-based approval workflow and a Git audit trail. Use Gitless automation if you want to avoid Git write permissions and reduce complexity by upgrading resources directly in the cluster.

  5. What is Gitless GitOps?

    main

    Gitless GitOps decouples the developer source of truth (Git) from the runtime dependency chain. Instead of clusters cloning Git repositories directly, CI processes package rendered Kubernetes configuration as OCI artifacts and push them to a container registry. Flux then pulls these pre-packaged artifacts using the OCIRepository resource.

    Delivery Path: Git source -> CI build -> OCI registry -> Flux clusters

  6. What is a ResourceSet and how does it work?

    main

    A ResourceSet (managed by flux-operator with apiVersion: fluxcd.controlplane.io/v1) is a mechanism for generating Kubernetes resources from a matrix of input values using a template-based approach. It is primarily used for multi-tenant orchestration, fleet management, and self-service platforms.

    It works by taking a set of inputs and applying them to a list of resources (or a resourcesTemplate). For every entry in the input matrix, the ResourceSet generates a unique set of Kubernetes objects.

    apiVersion: fluxcd.controlplane.io/v1
    kind: ResourceSet
    metadata:
      name: apps
      namespace: flux-system
    spec:
      inputs:
        - tenant: "frontend"
        - tenant: "backend"
      resources:
        - apiVersion: v1
          kind: Namespace
          metadata:
            name: << inputs.tenant >>
  7. Use Step-Based Reconciliation for ordered resource application

    main

    Instead of a flat list of resources, you can use spec.steps to define an ordered sequence of up to 20 named steps. Each step's resources are applied and health-checked to completion before the next step begins. This provides in-ResourceSet ordering without the latency of dependsOn between multiple objects.

    Key Rules:

    • spec.steps is mutually exclusive with resources and resourcesTemplate.
    • Each step can contain its own resources or resourcesTemplate using << >> templating.
    • A resource can only be defined in exactly one step; duplicates cause build failures.
    • Step names must be unique DNS labels (max 63 chars).
    • Use steps for internal ordering (e.g., Namespace $\rightarrow$ RBAC $\rightarrow$ App).
    • Use dependsOn for ordering between different ResourceSet objects.
    spec:
      steps:
        - name: step-one
          resources:
            - apiVersion: v1
              kind: ConfigMap
              ...
        - name: step-two
          resources:
            - apiVersion: v1
              kind: Secret
              ...
  8. Multi-Repo Pattern (Git-based)

    main

    This pattern uses separate repositories for fleet management, infrastructure, and applications. It is ideal for organizations with distinct platform and application teams.

    Key Characteristics

    • Fleet Repo Orchestration: The fleet repository creates GitRepository objects that point to the specific infrastructure and application repositories.
    • RBAC Isolation: Each tenant is assigned its own ServiceAccount with scoped RoleBinding.
    • Variable Injection: Uses postBuild.substituteFrom to inject cluster variables (like environment or domain) from ConfigMaps.
    • Image Automation: ImageUpdateAutomation runs within the fleet repository to push updates to the infrastructure or application repositories.

    Typical Repository Structure

    • fleet-repo: Owns cluster definitions and tenant orchestration.
    • infra-repo: Owns infrastructure components (e.g., cert-manager) and includes update/ for image automation.
    • apps-repo: Owned by dev teams; contains application manifests and image update policies.
    fleet-repo/
    ├── clusters/
    │   ├── staging/
    │   │   ├── flux-system/
    │   │   ├── runtime-info.yaml
    │   │   ├── infra-tenant.yaml
    │   │   └── apps-tenant.yaml
    │   └── production/
    ├── tenants/
    │   ├── infra/
    │   │   └── components/
    │   │       ├── source.yaml
    │   │       └── sync.yaml
    │   └── apps/
    │       └── components/
    │           └── <app>/
    │               ├── namespace.yaml
    │               ├── rbac.yaml
    │               └── sync.yaml
    
    infra-repo/
    ├── components/
    │   └── <component>/
    │       ├── controllers/
    │       └── configs/
    └── update/
    
    apps-repo/
    ├── components/
    │   └── <app>/
    │       ├── base/
    │       ├── staging/
    │       └── production/
    └── update/
  9. Implement Controller Sharding

    main

    The spec.sharding configuration horizontally partitions reconciliation across multiple controller replicas. This is useful for clusters with very large numbers of Flux resources.

    Each shard processes resources that carry a matching shard label (default key: sharding.fluxcd.io/key).

    Configuration Options:

    FieldTypeDescription
    sharding.keystringLabel key used to shard resources (default sharding.fluxcd.io/key)
    sharding.shards[]stringShard names (at least one)
    sharding.storagestringephemeral (emptyDir, default) or persistent (PVC). If persistent, spec.storage must be set

    Example Configuration:

    spec:
      sharding:
        key: sharding.fluxcd.io/key
        shards:
          - shard1
          - shard2
        storage: ephemeral

    Assigning a resource to a shard: Add the label to the resource: sharding.fluxcd.io/key: shard1.

  10. Directory-Driven Monorepo (Flux Operator, Gitless)

    main

    In this pattern, the Flux Operator generates the delivery pipeline directly from the directory structure. No Flux Kustomization is written by hand; adding a directory deploys it, and removing it prunes it.

    How it Works

    1. An ArtifactGenerator with a pathPattern produces one labeled ExternalArtifact per <thing>/envs/<env> directory.
    2. A ResourceSetInputProvider of type: ExternalArtifact exports one input per artifact.
    3. A ResourceSet templates a Flux Kustomization per input.
    4. Usually, the entire setup is pushed as one OCI artifact per cluster using a FluxInstance with sync.kind: OCIRepository, meaning the cluster never reads Git directly.

    Key Characteristics

    • Environment Types:
      • Cluster env (dev/prod): Selected via flux-vars to pick infra/**/envs/<env>.
      • App env (test/staging/prod): A namespace apps-<app_env> hosting instances of apps.
    • Ordering: Managed at the ResourceSet level: infra-core → infra-controllers → apps-<app_env> → per-app ResourceSets. Use wait: true and dependsOn with namespace settings.
    • App Composition: Apps combine manifests from a generated ExternalArtifact with image versions from an OCIArtifactTag provider pinned via spec.images (newTag + digest).
    • Parameterization: Only clusters/<cluster>/ differs between clusters; all other paths are parameterized by ${env}, ${cluster_registry}, ${app_registry}, ${app_env}, and ${app_semver}.

    Audit Checklist

    When auditing this pattern, check for:

    • source-watcher being enabled.
    • base + overlay being copied by every pathPattern generator.
    • YAML-safe substituted values.
    • Plain image names in spec.images[].name.
    • namespace defined on ResourceSet dependsOn.
    • wait: true and reconcileTimeout on every ResourceSet.
    kubernetes/
    ├── clusters/<cluster>/
    │   ├── flux-instance.yaml
    │   ├── flux-vars.yaml
    │   ├── infra-reconcilers.yaml
    │   └── apps-<app_env>-reconcilers.yaml
    ├── infra/
    │   ├── reconcilers/
    │   │   ├── core.yaml
    │   │   ├── controllers.yaml
    │   │   └── configs.yaml
    │   ├── core/{base,envs/<env>}/
    │   └── components/<name>/
    │       ├── controllers/{base,envs/<env>}/
    │       └── configs/{base,envs/<env>}/
    └── apps/
        ├── reconcilers/
        │   ├── artifacts.yaml
        │   ├── env.yaml
        │   └── <app>.yaml
        └── <app>/{base,envs/<app_env>}/
  11. Configure Flux components

    main

    The components list in a FluxInstance determines which controllers are installed.

    Default components:

    • source-controller
    • kustomize-controller
    • helm-controller
    • notification-controller

    Optional components:

    • image-reflector-controller and image-automation-controller: Used for image automation (typically on dedicated "update" clusters).
    • source-watcher: Controller for the ArtifactGenerator CRD. It composes/decomposes artifacts from multiple sources (GitRepository, OCIRepository, Bucket) into ExternalArtifact resources. Required for monorepo decomposition and multi-source composition.
  12. Choose between Git-based and Gitless Image Automation

    main

    Flux provides two ways to automate image updates:

    1. Git-based Automation: Uses ImageRepository + ImagePolicy + ImageUpdateAutomation. It commits tag bumps directly to Git using $imagepolicy YAML markers.

      • Use when: You require PR-based approval for version bumps or need a Git audit trail of every deployed version.
      • Requires: image-reflector-controller and image-automation-controller.
    2. Gitless Automation: Uses ResourceSet + ResourceSetInputProvider (with type: OCIArtifactTag). It re-renders downstream HelmRelease or Kustomization resources without modifying Git.

      • Use when: You want to avoid managing bot credentials in Git, reduce poll lag, or when the image tag is stored in Helm values and varies per cluster.
      • Benefit: This is the recommended default for the Flux Operator.