Select Page
last updated on May 24, 2024

In this guide, we will walk you through the process of configuring a private Git repository in Flux CD to deploy your Kubernetes applications. This involves several steps, including Installing Git and Flux CD, Setting up SSH Authentication, and Bootstrapping your Kubernetes Cluster with Flux CD. Each step is crucial for ensuring a seamless and secure deployment process.

Let’s see the detailed explanation of each step!

1. Installing Git

Git is a version control system that allows you to manage your code and configuration files efficiently. It’s the foundation for setting up a GitOps workflow with Flux CD.

Installing GIT in Windows

  1. Download the latest Git for Windows Installer from Git for Windows.
  2. Run the installer and follow the prompts to complete the installation.
  3. Once installed, use Git Bash to run the Git commands.

Installing GIT in MacOS

  1. Open the Terminal.
  2. Install Git using Homebrew:
					brew install git

Installing GIT in Ubuntu Linux

1. Open the Terminal.
2. Update the package manager and install Git:

					sudo apt update
  sudo apt install git -y


3. Verify the installation:

					git --version

Configuring Git

Configuring Git with your user information ensures that your commits are correctly attributed to you, which is important for tracking changes and collaboration. Set up your Git username and email using the following commands:

					git config --global "Your Name"
git config --global ""


2. Setting Up SSH Authentication

SSH authentication allows you to securely interact with the remote Git repositories without entering your username and password each time. This is essential for automating deployments. Follow the steps below in order to set up SSH authentication. 

1. Generate an SSH key pair:

					ssh-keygen -t ed25519 -C ""

2. Start the SSH agent and add your SSH key:

					eval "$(ssh-agent -s)"
    ssh-add ~/.ssh/id_ed25519


3. Copy the public key to your clipboard:

					cat ~/.ssh/

4. Add the SSH key to your GitHub account

  1. Log in to your GitHub account.
  2. In the upper-right corner of any page, click your profile photo, then click Settings.
  3. In the left sidebar, click SSH and GPG keys.
  4. Click the New SSH key.
  5. In the Title field, add a descriptive label for the new key.
  6. Paste your key into the Key field.
  7. Click Add SSH key.

3. Installing Flux CD

Installing Flux CD in macOS and Linux

1. Open Terminal and install Flux CD using Homebrew:

					brew install fluxcd/tap/flux

Installing Flux CD in Windows

1. Use Chocolatey to install Flux CD:

					choco install flux

4. Setting Up Your Git Repository

A Git repository is where Flux CD will store its configuration and state. This repository acts as the single source of truth for your deployments.

  1. Create a new repository on GitHub (or your preferred Git provider).
  2. Clone the repository to your local machine:
					git clone your_username/your_repo.git
cd your_repo


5. Preparing the Directory Structure

Flux CD requires a specific directory structure to locate and manage its configuration files. Setting up this structure is essential for Flux CD to function correctly.

1. Create the necessary directories and files for Flux CD using the given commands:

					mkdir -p clusters/my-cluster/flux-system
    cd clusters/my-cluster/flux-system
    touch gotk-components.yaml gotk-sync.yaml kustomization.yaml


2. Add the following content to `kustomization.yaml` as given below:

    kind: Kustomization
    - gotk-components.yaml
    - gotk-sync.yaml


When Flux CD is installed in a Kubernetes cluster, it creates several Custom Resource Definitions (CRDs), including one called `GitRepository`. This CRD tells Flux which Git repository to watch for configuration changes. The repository is monitored by Flux controllers, which apply any detected changes to the cluster. The `kustomization.yaml` file helps Flux know where to find the configuration files and how to apply them.

6. Creating a Personal Access Token

A personal access token (PAT) is needed for Flux CD to authenticate with your Git repository. This token allows Flux CD to push changes to your repository securely. The PAT will be stored as a secret in the `flux-system` namespace to contain the credentials needed to access the repository.

7. Creating a Personal Access Token on GitHub

  • Log in to your GitHub account.
  • In the upper-right corner of any page, click your profile photo, then click Settings.
  • In the left sidebar, click Developer Settings.
  • Click on Personal access tokens.
  • Click on Generate new token.
  • Give your token a descriptive name, select the expiration date, and check the necessary scopes (usually `repo` and `workflow`).
  • Click Generate token.
  • Copy the token to your clipboard as you won’t be able to see the token again. 

Storing the PAT as a Secret in the `flux-system` Namespace:

1. Export the token as an environment variable:

					export GITHUB_TOKEN=your_token_value

2. Create a Kubernetes secret to store the PAT:

					 kubectl create secret generic flux-system \
      --namespace=flux-system \


During the bootstrap process, Flux CD uses the Kubernetes secret containing the PAT to authenticate and interact with the private repository securely. This ensures that your deployments are automated and synchronized with your Git repository.

8. Bootstrapping Flux CD

Bootstrapping Flux CD installs its components on your Kubernetes cluster and configures it to sync with your Git repository. This step is crucial for setting up the GitOps workflow.

1. Use the Flux CLI to bootstrap your cluster:

					 flux bootstrap github \
      --owner=your_username \
      --repository=your_repo \
      --branch=main \
      --path=clusters/my-cluster \


During the bootstrap process, Flux CD creates a `GitRepository` CRD that contains the URL of your Git repository and other metadata, such as the branch to watch. It also creates a Kubernetes Secret to store the personal access token securely. This allows Flux to authenticate and interact with the private repository.

9. Verifying the Installation

Verifying the installation ensures that Flux CD has been correctly installed and configured on your Kubernetes cluster. This step helps in troubleshooting any issues earlier.

1. Check the Flux CD components in your Kubernetes cluster:

					kubectl get pods -n flux-system

Now, you have successfully configured a private Git repository in Flux CD to deploy Kubernetes applications. This setup ensures that your deployments are automated and synchronized with your Git repository, following the principles of GitOps. For more detailed information, refer to Flux CD documentation.

About OpsMx

OpsMx is a leading innovator and thought leader in the Continuous Delivery space. OpsMx’s Solution for Flux helps DevOps teams manage their Flux deployments at scale.

Talk to OpsMx’s FluxCD experts about any questions that you may have around Flux, GitOps-style deployments, Kubernetes, or DevSecOps. Our services enable the largest and most innovative companies to optimize their (GitOps) delivery pipelines.


Submit a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.