This guide assumes you have some understanding of the core concepts and have read the introduction to Flux.
The core concepts used in this guide are [GitOps](../core-concepts/index.md#gitops), [Sources](../core-concepts/index.md#sources), [Kustomization](../core-concepts/index.md#kustomization).
In this tutorial, you will deploy an application to a kubernetes cluster with Flux and manage the cluster in a complete GitOps manner. You'll be using a dedicated Git repository e.g. `fleet-infra` to manage the Kubernetes clusters. All the manifest will be pushed to this repository and then applied by Flux.
## Prerequisites
You will need two Kubernetes clusters version 1.16 or newer and kubectl version 1.18.
In order to follow the guide, you will need one Kubernetes cluster version 1.16 or newer and kubectl version 1.18.
For a quick local test, you can use [Kubernetes kind](https://kind.sigs.k8s.io/docs/user/quick-start/).
Any other Kubernetes setup will work as well though.
In order to follow the guide you'll need a GitHub account and a
Flux is installed in a complete GitOps way and its manifest will be pushed to the repository, so you will also need a GitHub account and a
that can create repositories (check all permissions under `repo`).
that can create repositories (check all permissions under `repo`) to enable Flux do this.
Export your GitHub personal access token and username:
@ -52,24 +58,13 @@ profile:
`zsh`, `fish`, and `powershell` are also supported with their own sub-commands.
## GitOps workflow
You'll be using a dedicated Git repository e.g. `fleet-infra` to manage one or more Kubernetes clusters.
This guide assumes that you have two clusters, one for staging and one for production.
Using the Flux CLI you'll do the following:
- configure each cluster to synchronise with a directory inside the fleet repository
- register app sources (git repositories) that contain plain Kubernetes manifests or Kustomize overlays
- configure app deployments on both clusters (pre-releases on staging, semver releases on production)
## Install Flux components
## Staging bootstrap
Create the staging cluster using Kubernetes kind or set the kubectl context to an existing cluster:
Create the cluster using Kubernetes kind or set the kubectl context to an existing cluster:
```sh
kind create cluster --name staging
kubectl cluster-info --context kind-staging
kind create cluster
kubectl cluster-info --context kind-kind
```
Verify that your staging cluster satisfies the prerequisites with:
@ -89,7 +84,7 @@ flux bootstrap github \
--owner=$GITHUB_USER \
--repository=fleet-infra \
--branch=main \
--path=staging-cluster \
--path=./clusters/my-cluster \
--personal
```
@ -98,8 +93,8 @@ flux bootstrap github \
you can use `--arch=arm` for ARMv7 32-bit container images
and `--arch=arm64` for ARMv8 64-bit container images.
The bootstrap command creates a repository if one doesn't exist, and
commits the manifests for the Flux components to the default branch at the specified path.
The bootstrap command creates a repository if one doesn't exist,
commits the manifests for the Flux components to the default branch at the specified path, and installs the Flux components.
Then it configures the target cluster to synchronize with the specified path inside the repository.
If you wish to create the repository under a GitHub organization:
@ -111,7 +106,7 @@ flux bootstrap github \
--branch=<organizationdefaultbranch> \
--team=<team1-slug> \
--team=<team2-slug> \
--path=staging-cluster
--path=./clusters/my-cluster
```
Example output:
@ -148,102 +143,104 @@ If you prefer GitLab, export `GITLAB_TOKEN` env var and use the command [flux bo
You can target a specific Flux [version](https://github.com/fluxcd/flux2/releases)
with `flux bootstrap --version=<semver>`.
## Staging workflow
## Clone the git repository
We are going to be managing the application in a GitOps manner with the git repository. The Flux manifests generated by the CLI will be pushed to the git repository. Instead of applying the manifests directly to the cluster, Flux will apply it for us instead :).
Clone the repository with:
Therefore, we need to clone the repository to our local machine.
Create a git source pointing to a public repository master branch:
## Add podinfo repository to Flux
We will be using a public repository [github.com/stefanprodan/podinfo](https://github.com/stefanprodan/podinfo), podinfo is a tiny web application made with Go.
Create a GitRepository manifest pointing to the repository's master branch with Flux CLI.