> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Demo FluxCD Installation

> Guide to install Flux v2 CLI, deploy Flux controllers into Kubernetes, and bootstrap GitOps with GitHub by creating a repository, deploy key, and syncing manifests

This guide shows how to install the Flux v2 CLI, deploy Flux controllers into a Kubernetes cluster, and bootstrap Flux to manage itself from a GitHub repository. Steps were performed using Visual Studio Code on Ubuntu 18.04 under Windows Subsystem for Linux (WSL) with Docker Desktop as the Kubernetes provider (single-node cluster). The instructions below are applicable to most Linux/macOS development environments and can be adapted for other editors or terminals.

Environment summary

| Component | Details |
| -: | - |
| OS | Ubuntu 18.04 (WSL) |
| Kubernetes | Docker Desktop single-node cluster (example: v1.25.4) |
| Docker | Docker Desktop |
| Editor | Visual Studio Code (any editor/terminal works) |

Docker Desktop must have Kubernetes enabled. The Docker Desktop settings (Kubernetes enabled) are shown here:

![A screenshot of Docker Desktop's Settings on the Kubernetes tab, showing options like "Enable Kubernetes" and a highlighted "Reset Kubernetes Cluster" button. The left sidebar lists other settings such as General, Resources, Docker Engine, and Extensions.](https://mintcdn.com/kodekloud-c4ac6d9a/AyhVWHpoMIYCWiei/images/GitOps-with-FluxCD/Flux-Overview/Demo-FluxCD-Installation/docker-desktop-kubernetes-reset-button.jpg?fit=max\&auto=format\&n=AyhVWHpoMIYCWiei\&q=85\&s=d6bdbdeaad434af32301a2f7e5a5e03b)

Verify the cluster and node

```console theme={null}
root ~
➜ k get nodes
NAME              STATUS   ROLES         AGE    VERSION
docker-desktop    Ready    control-plane 3d22h  v1.25.4
```

Installing the Flux CLI

1. Confirm the `flux` CLI is not installed:

```console theme={null}
root ~
➜ flux -v
Command 'flux' not found, did you mean:
  command 'flix' from deb epix
  command 'flex' from deb flex
  command 'flex' from deb flex-old
Try: apt install <deb name>
```

2. Install the Flux CLI using the official install script and enable Bash completion:

```bash theme={null}
curl -s https://fluxcd.io/install.sh | sudo bash
. <(flux completion bash)
```

3. Verify the installed CLI version:

```console theme={null}
root ~
➜ flux -v
flux version 0.41.2
```

Note: At this point the CLI is installed, but Flux controllers are not yet deployed into your cluster. Running `flux version` without cluster components will report:

```console theme={null}
root ~
➜ flux version
✗ no deployments found in flux-system namespace
```

Bootstrapping Flux to GitHub (GitOps)

Flux provides a `bootstrap` command that installs the Flux controllers into your cluster and configures them to sync with a Git repository. The GitHub bootstrap requires a GitHub Personal Access Token (PAT) with the appropriate scopes (typically `repo` for repository creation/management and deploy key configuration).

Quick example of the bootstrap command (placeholders shown in backticks):

```bash theme={null}
flux bootstrap github [flags]

# Example usage with environment variable:
export GITHUB_TOKEN=`<your-token>`

flux bootstrap github \
  --owner=`<owner>` \
  --repository=`<repository>` \
  --path=`clusters/my-cluster` \
  --personal
```

Important flags

| Flag | Purpose |
| - | - |
| `--owner` | GitHub user or organization name (owner of the repository) |
| `--repository` | Repository name (Flux will create it if it doesn't exist) |
| `--path` | Path inside the repo where Flux will place the cluster manifests (e.g. `flux-clusters/dev-cluster`) |
| `--personal` | Treat `--owner` as a personal user instead of an organization |
| `--private` | Create the repo as private if true (default is true) |
| `--read-write-key` | Configure a deploy key with read/write access if necessary |

Create a GitHub Personal Access Token

Create a PAT with the minimum scopes required for bootstrap (commonly `repo`). On GitHub: Settings → Developer settings → Personal access tokens → [Generate new token (classic)](https://github.com/settings/tokens/new?type=classic). Copy and store the token securely — GitHub will not show it again after you leave the page.

![A screenshot of GitHub’s "New Personal Access Token" page in dark mode, showing the Expiration set to "No expiration" and a highlighted recommendation to set an expiry. The OAuth scopes list is visible with "repo" and several repo-related permissions checked.](https://mintcdn.com/kodekloud-c4ac6d9a/AyhVWHpoMIYCWiei/images/GitOps-with-FluxCD/Flux-Overview/Demo-FluxCD-Installation/github-pat-dark-no-expiration-repo.jpg?fit=max\&auto=format\&n=AyhVWHpoMIYCWiei\&q=85\&s=52ec065cdf2ee090e61e36f8edda8c52)

For security, grant tokens the minimum scopes required and set an expiry. The bootstrap process typically requires the `repo` scope to create a repository and add deploy keys; consider using a short-lived token if possible.

Run the bootstrap command

Replace the placeholders below with your own values (owner, repository, path, and token):

```bash theme={null}
export GITHUB_TOKEN=`<your-token>`

flux bootstrap github \
  --owner=sidd-harth-2 \
  --repository=block-buster \
  --path=flux-clusters/dev-cluster \
  --personal=true \
  --private=false
```

What happens during bootstrap

1. Flux connects to GitHub and creates (or uses) the specified repository.
2. Flux generates component manifests (namespace, CRDs, controllers).
3. Flux installs controllers into the `flux-system` namespace.
4. Flux generates a deploy key pair: the public key is added to the GitHub repo; the private key is stored in a Kubernetes Secret in `flux-system`.
5. Flux commits generated manifests into the repository and pushes them to the `main` branch.
6. Flux reconciles the Kustomization to apply manifests and validates component health.

Sample trimmed bootstrap output (annotated)

```console theme={null}
✓ cloned repository
▸ generating component manifests
✓ generated component manifests
✓ component manifests are up to date
▸ installing components in "flux-system" namespace
✓ installed components
✓ reconciled components
▸ determining if source secret "flux-system/flux-system" exists
▸ generating source secret
✓ public key: ecdsa-sha2-nistp384 AAAAE2VjZ...
✓ configured deploy key "flux-system-main-flux-system-./flux-clusters/dev-cluster" for "https://github.com/sidd-harth-2/block-buster"
▸ applying source secret "flux-system/flux-system"
✓ reconciled source secret
▸ generating sync manifests
✓ generated sync manifests
✓ committed sync manifests to "main" ("d820019258ccdf17a7cb80b703142a573232c69c")
▸ pushing sync manifests to "https://github.com/sidd-harth-2/block-buster.git"
▸ applying sync manifests
✓ reconciled sync configuration
◉ waiting for Kustomization "flux-system/flux-system" to be reconciled
✓ Kustomization reconciled successfully
✓ confirming components are healthy
✓ helm-controller: deployment ready
✓ kustomize-controller: deployment ready
✓ notification-controller: deployment ready
✓ source-controller: deployment ready
✓ all components are healthy
```

After bootstrap completes, Flux controllers are running in the cluster and the generated manifests have been pushed into the Git repo.

Inspect the created repository

Clone the repository created by bootstrap:

```bash theme={null}
git clone https://github.com/sidd-harth-2/block-buster.git
```

Example clone output:

```console theme={null}
Cloning into 'block-buster'...
remote: Enumerating objects: 13, done.
remote: Counting objects: 100% (13/13), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 13 (delta 0), reused 13 (delta 0), pack-reused 0
Unpacking objects: 100% (13/13), done.
```

Repository layout (typical)

* `flux-clusters/dev-cluster/flux-system/` — contains generated manifests such as:
  * `gotk-components.yaml`
  * `gotk-sync.yaml`
  * Kustomization YAML files

Example excerpt from `gotk-components.yaml` (auto-generated by Flux):

```yaml theme={null}
---
# This manifest was generated by flux. DO NOT EDIT.
# Flux Version: v0.41.2
# Components: source-controller,kustomize-controller,helm-controller,notification-controller
apiVersion: v1
kind: Namespace
metadata:
  labels:
    app.kubernetes.io/instance: flux-system
    app.kubernetes.io/part-of: flux
    app.kubernetes.io/version: v0.41.2
    pod-security.kubernetes.io/warn: restricted
    pod-security.kubernetes.io/warn-version: latest
  name: flux-system
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  annotations:
    controller-gen.kubebuilder.io/version: v0.11.1
  labels:
    app.kubernetes.io/component: notification-controller
    app.kubernetes.io/instance: flux-system
    app.kubernetes.io/part-of: flux
    app.kubernetes.io/version: v0.41.2
  name: alerts.notification.toolkit.fluxcd.io
```

Verify Flux components in the cluster

1. Confirm the `flux-system` namespace exists:

```console theme={null}
root ~
➜ k get ns
NAME               STATUS    AGE
default            Active    9m54s
flux-system        Active    3m30s
kube-node-lease    Active    9m56s
kube-public        Active    9m56s
kube-system        Active    9m56s
```

2. Inspect resources in `flux-system`:

```bash theme={null}
kubectl -n flux-system get all
```

You should see Deployments, ReplicaSets, and Pods for:

* source-controller
* kustomize-controller
* helm-controller
* notification-controller

Also observe a Secret (for example `flux-system`) that holds the private deploy key. The public key is configured as a deploy key in the GitHub repository.

3. List Flux-related CRDs:

```console theme={null}
root ~
➜ k get crds | grep -i flux
alerts.notification.toolkit.fluxcd.io        2023-04-05T19:16:44Z
buckets.source.toolkit.fluxcd.io            2023-04-05T19:16:44Z
gitrepositories.source.toolkit.fluxcd.io    2023-04-05T19:16:44Z
helmcharts.source.toolkit.fluxcd.io         2023-04-05T19:16:44Z
helmreleases.helm.toolkit.fluxcd.io         2023-04-05T19:16:44Z
helmrepositories.source.toolkit.fluxcd.io   2023-04-05T19:16:44Z
kustomizations.kustomize.toolkit.fluxcd.io  2023-04-05T19:16:44Z
ocirepositories.source.toolkit.fluxcd.io    2023-04-05T19:16:44Z
providers.notification.toolkit.fluxcd.io    2023-04-05T19:16:44Z
receivers.notification.toolkit.fluxcd.io    2023-04-05T19:16:44Z
```

4. Check CLI and controller versions:

```console theme={null}
root ~
➜ flux version
flux: v0.41.2
helm-controller: v0.31.2
kustomize-controller: v0.35.1
notification-controller: v0.33.0
source-controller: v0.36.1
```

Summary

* You installed the `flux` CLI and bootstrapped Flux to your Kubernetes cluster using `flux bootstrap github`.
* Bootstrap created (or used) a GitHub repository, generated and committed Flux manifests, installed Flux controllers into the `flux-system` namespace, created CRDs, and configured a deploy key so Flux can sync with the repository.
* The repository contains Flux-generated manifests (e.g., `gotk-components.yaml`, `gotk-sync.yaml`, and Kustomizations). You can now edit the repo to add your cluster manifests and let Flux reconcile and apply changes automatically (GitOps).

Links and references

* Flux v2 documentation: [https://fluxcd.io/docs/](https://fluxcd.io/docs/)
* Flux CLI installation: [https://fluxcd.io/installation/](https://fluxcd.io/installation/)
* GitHub Personal Access Token docs: [https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token)
* Kubernetes documentation: [https://kubernetes.io/docs/](https://kubernetes.io/docs/)

> **[Watch Video](https://learn.kodekloud.com/user/courses/gitops-with-fluxcd/module/44949c1c-edf6-4432-81ce-78d709c30af5/lesson/384a3004-5916-45a6-adae-a8e418373118)**

> **[Practice Lab](https://learn.kodekloud.com/user/courses/gitops-with-fluxcd/module/44949c1c-edf6-4432-81ce-78d709c30af5/lesson/14105c0e-4073-4080-aebb-c8941ebc00c8)**


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.