-
Notifications
You must be signed in to change notification settings - Fork 635
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Stefan Prodan <[email protected]>
- Loading branch information
1 parent
4c94e8e
commit 5335d7b
Showing
1 changed file
with
51 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,32 +42,57 @@ flux check --pre | |
Using the `flux bootstrap` command you can install Flux on a | ||
Kubernetes cluster and configure it to manage itself from a Git | ||
repository. | ||
|
||
The bootstrap creates a Git repository if one doesn't exist and | ||
commits the Flux components manifests to the main branch. Then it | ||
configures the target cluster to synchronize with that repository by | ||
setting up SSH deploy keys. | ||
|
||
If the Flux components are present on the cluster, the bootstrap | ||
command will perform an upgrade if needed. The bootstrap is | ||
idempotent, it's safe to run the command as many times as you want. | ||
|
||
You can choose what components to install and for which cluster with: | ||
!!! hint "Multi-arch images" | ||
The component images are published as [multi-arch container images](https://docs.docker.com/docker-for-mac/multi-arch/) | ||
with support for Linux `amd64`, `arm64` and `armv7` (e.g. 32bit Raspberry Pi) | ||
architectures. | ||
|
||
### Generic Git Server | ||
|
||
The `bootstrap git` command takes an existing Git repository, clones it and | ||
commits the Flux components manifests to the specified branch. Then it | ||
configures the target cluster to synchronize with that repository. | ||
|
||
Run bootstrap for a Git repository and authenticate with your SSH agent: | ||
|
||
```sh | ||
flux bootstrap <GIT-PROVIDER> \ | ||
--components=source-controller,kustomize-controller,helm-controller,notification-controller \ | ||
--components-extra=image-reflector-controller,image-automation-controller \ | ||
flux bootstrap git \ | ||
--url=ssh://git@<host>/<org>/<repository> \ | ||
--branch=<my-branch> \ | ||
--path=clusters/my-cluster | ||
``` | ||
|
||
!!! hint "Multi-arch images" | ||
The component images are published as [multi-arch container images](https://docs.docker.com/docker-for-mac/multi-arch/) | ||
with support for Linux `amd64`, `arm64` and `armv7` (e.g. 32bit Raspberry Pi) | ||
architectures. | ||
The above command will generate a SSH key (defaults to RSA 2048 but can be changed with `--ssh-key-algorithm`), | ||
and it will prompt you to add the SSH public key as a deploy key to your repository. | ||
|
||
If SSH agent is not available on your machine, you can provide a passwordless private key using | ||
`--private-key-file=<path/to/private.key>`. | ||
|
||
!!! hint "Bootstrap options" | ||
There are many options available when bootstrapping Flux, such as installing a subset of Flux components, | ||
setting the Kubernetes context, changing the Git author name and email, enabling Git submodules, and more. | ||
To list all the available options run `flux bootstrap git --help`. | ||
|
||
If your Git server doesn't support SSH, you can run bootstrap for Git over HTTPS: | ||
|
||
```sh | ||
flux bootstrap git \ | ||
--url=https://<host>/<org>/<repository> \ | ||
--username=<my-username> \ | ||
--password=<my-password> \ | ||
--token-auth=true \ | ||
--path=clusters/my-cluster | ||
``` | ||
|
||
If your Git server uses a self-signed TLS certificate, you can specify the CA file with | ||
`--ca-file=<path/to/ca.crt>`. | ||
|
||
If you wish to install a specific version, use the Flux | ||
[release tag](https://github.com/fluxcd/flux2/releases) e.g. `--version=v0.9.0`. | ||
[release tag](https://github.com/fluxcd/flux2/releases) e.g. `--version=v0.12.0`. | ||
|
||
If you wish to deploy the Flux components onto | ||
[tainted Kubernetes nodes](https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/), | ||
|
@@ -84,24 +109,25 @@ cluster e.g. `clusters/staging` and `clusters/production`: | |
│ ├── gotk-components.yaml | ||
│ ├── gotk-sync.yaml | ||
│ └── kustomization.yaml | ||
└── production-cluster # <- path=clusters/production | ||
└── production # <- path=clusters/production | ||
└── flux-system | ||
``` | ||
|
||
After running bootstrap you can place Kubernetes YAMLs inside a dir under path | ||
e.g. `clusters/staging/my-app`, and Flux will reconcile them on your cluster. | ||
|
||
!!! hint "Change the default branch" | ||
If you wish to change the branch to something else than main, create the repository manually, | ||
push a branch to origin and then use `flux bootstrap <GIT-PROVIDER> --branch=your-branch`. | ||
|
||
For examples on how you can structure your Git repository see: | ||
|
||
* [flux2-kustomize-helm-example](https://github.com/fluxcd/flux2-kustomize-helm-example) | ||
* [flux2-multi-tenancy](https://github.com/fluxcd/flux2-multi-tenancy) | ||
|
||
### GitHub and GitHub Enterprise | ||
|
||
The `bootstrap github` command creates a GitHub repository if one doesn't exist and | ||
commits the Flux components manifests to specified branch. Then it | ||
configures the target cluster to synchronize with that repository by | ||
setting up a SSH deploy key or by using token-based authentication. | ||
|
||
Generate a [personal access token](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line) | ||
that can create repositories by checking all permissions under `repo`. | ||
|
||
|
@@ -166,6 +192,11 @@ flux bootstrap github \ | |
|
||
### GitLab and GitLab Enterprise | ||
|
||
The `bootstrap gitlab` command creates a GitLab repository if one doesn't exist and | ||
commits the Flux components manifests to specified branch. Then it | ||
configures the target cluster to synchronize with that repository by | ||
setting up a SSH deploy key or by using token-based authentication. | ||
|
||
Generate a [personal access token](https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html) | ||
that grants complete read/write access to the GitLab API. | ||
|
||
|
@@ -274,162 +305,6 @@ the CLI will use the manifests embedded in its binary instead of downloading | |
them from GitHub. You can determine which version you'll be installing, | ||
with `flux --version`. | ||
|
||
### Generic Git Server | ||
|
||
For other Git providers such as Bitbucket, Gogs, Gitea, Azure DevOps, etc | ||
you can manually setup the repository and deploy key. | ||
|
||
Create a Git repository and clone it locally: | ||
|
||
```sh | ||
git clone ssh://<host>/<org>/my-repository | ||
cd my-repository | ||
``` | ||
|
||
Create a directory inside the repository: | ||
|
||
```sh | ||
mkdir -p ./clusters/my-cluster/flux-system | ||
``` | ||
|
||
Generate the Flux manifests with: | ||
|
||
```sh | ||
flux install \ | ||
--export > ./clusters/my-cluster/flux-system/gotk-components.yaml | ||
``` | ||
|
||
Commit and push the manifest to the master branch: | ||
|
||
```sh | ||
git add -A && git commit -m "add components" && git push | ||
``` | ||
|
||
Apply the manifests on your cluster: | ||
|
||
```sh | ||
kubectl apply -f ./clusters/my-cluster/flux-system/gotk-components.yaml | ||
``` | ||
|
||
Verify that the controllers have started: | ||
|
||
```sh | ||
flux check | ||
``` | ||
|
||
Create a `GitRepository` object on your cluster by specifying the SSH address of your repo: | ||
|
||
```sh | ||
flux create source git flux-system \ | ||
--url=ssh://git@<host>/<org>/<repository> \ | ||
--ssh-key-algorithm=ecdsa \ | ||
--ssh-ecdsa-curve=p521 \ | ||
--branch=master \ | ||
--interval=1m | ||
``` | ||
|
||
You will be prompted to add a deploy key to your repository. | ||
If you don't specify the SSH algorithm, then `flux` will generate an RSA 2048 bits key. | ||
|
||
!!! hint "Azure DevOps" | ||
Azure DevOps requires a non-default Git implementation (`libgit2`) to be enabled, so that the Git v2 protocol is supported. | ||
Note that this implementation does not support shallow cloning, and it is therefore advised to only resort to this option if a | ||
connection fails with the default configuration. | ||
|
||
Azure DevOps [only supports RSA SSH keys](https://developercommunity.visualstudio.com/t/support-non-rsa-keys-for-ssh-authentication/365980), | ||
you cannot use elliptic curve SSH keys like ecdsa or ed25519. | ||
|
||
Here is how to specify the `libgit2` implementation and generate a proper RSA key: | ||
|
||
```sh | ||
flux create source git flux-system \ | ||
--git-implementation=libgit2 \ | ||
--ssh-key-algorithm=rsa \ | ||
--ssh-rsa-bits=4096 \ | ||
--url=ssh://[email protected]/v3/<org>/<project>/<repository> \ | ||
--branch=main \ | ||
--interval=1m | ||
``` | ||
|
||
This config uses the `main` branch, but your repo may be older and need to specify `master` instead. | ||
|
||
Note that unlike `git`, Flux does not support the | ||
["shorter" scp-like syntax for the SSH protocol](https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols#_the_ssh_protocol) | ||
(e.g. `ssh.dev.azure.com:v3`). | ||
Use the [RFC 3986 compatible syntax](https://tools.ietf.org/html/rfc3986#section-3) instead: `ssh.dev.azure.com/v3`. | ||
|
||
The `flux create source git` command will prompt you to add a deploy key to your repository, but Azure DevOps | ||
[does not support repository or org-specific deploy keys](https://developercommunity.visualstudio.com/t/allow-the-creation-of-ssh-deploy-keys-for-vsts-hos/365747). | ||
You may add the deploy key to a user's personal SSH keys being mindful that removing them from the repo may revoke Flux's access. | ||
As an alternative, create a machine-user whose sole purpose is to store credentials for automation. | ||
Using a machine-user also has the benefit of being able to be read-only or restricted to specific repositories if that is needed. | ||
|
||
If you wish to use Git over HTTPS, then generate a personal access token and supply it as the password: | ||
|
||
```sh | ||
flux create source git flux-system \ | ||
--git-implementation=libgit2 \ | ||
--url=https://dev.azure.com/<org>/<project>/_git/<repository> \ | ||
--branch=master \ | ||
--username=git \ | ||
--password=${AZ_PAT_TOKEN} \ | ||
--interval=1m | ||
``` | ||
|
||
Please consult the [Azure DevOps documentation](https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs=preview-page) | ||
on how to generate personal access tokens for Git repositories. | ||
Azure DevOps PAT's always have an expiration date, so be sure to have some process for renewing or updating these tokens. | ||
Similar to the lack of repo-specific deploy keys, a user needs to generate a user-specific PAT. | ||
If you are using a machine-user, you can generate a PAT or simply use the machine-user's password which does not expire. | ||
|
||
If your Git server supports basic auth, you can set the URL to HTTPS and specify the credentials with: | ||
|
||
```sh | ||
flux create source git flux-system \ | ||
--url=https://<host>/<org>/my-repository \ | ||
--username=my-username \ | ||
--password=my-password \ | ||
--branch=master \ | ||
--interval=1m | ||
``` | ||
|
||
Create a `Kustomization` object on your cluster: | ||
|
||
```sh | ||
flux create kustomization flux-system \ | ||
--source=flux-system \ | ||
--path="./clusters/my-cluster" \ | ||
--prune=true \ | ||
--interval=10m | ||
``` | ||
|
||
Export both objects, generate a `kustomization.yaml`, commit and push the manifests to Git: | ||
|
||
```sh | ||
flux export source git flux-system \ | ||
> ./clusters/my-cluster/flux-system/gotk-sync.yaml | ||
|
||
flux export kustomization flux-system \ | ||
>> ./clusters/my-cluster/flux-system/gotk-sync.yaml | ||
|
||
cd ./clusters/my-cluster/flux-system && kustomize create --autodetect | ||
|
||
git add -A && git commit -m "add sync manifests" && git push | ||
``` | ||
|
||
To upgrade the Flux components to a newer version, download the latest `flux` binary, | ||
run the install command and commit the changes: | ||
|
||
```sh | ||
flux install \ | ||
--export > ./clusters/my-cluster/flux-system/gotk-components.yaml | ||
|
||
git add -A && git commit -m "update flux" && git push | ||
``` | ||
|
||
The source-controller will pull the changes on the cluster, then the kustomize-controller | ||
will perform a rolling update of all Flux components including itself. | ||
|
||
## Bootstrap with Terraform | ||
|
||
The bootstrap procedure can be implemented with Terraform using the Flux provider published on | ||
|