This repository was archived by the owner on Nov 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add Flux deployment kustomization #2375
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5401337
Add Flux deployment kustomization
stefanprodan da26b61
Add the readonly flags to deployment template
stefanprodan 8e4d2ca
Add git user and email flags to install docs
stefanprodan d1e0dc7
Move Kustomize install docs to a dedicated section
stefanprodan 9f4d520
Add Kustomize example repos to docs
stefanprodan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,161 @@ | ||
# How to bootstrap Flux using Kustomize | ||
|
||
This guide shows you how to use Kustomize to bootstrap Flux on a Kubernetes cluster. | ||
|
||
## Prerequisites | ||
|
||
You will need to have Kubernetes set up. For a quick local test, | ||
you can use `minikube` or `kubeadm`. Any other Kubernetes setup | ||
will work as well though. | ||
|
||
### A note on GKE with RBAC enabled | ||
|
||
If working on e.g. GKE with RBAC enabled, you will need to add a cluster role binding: | ||
|
||
```sh | ||
kubectl create clusterrolebinding "cluster-admin-$(whoami)" \ | ||
--clusterrole=cluster-admin \ | ||
--user="$(gcloud config get-value core/account)" | ||
``` | ||
|
||
## Prepare Flux installation | ||
|
||
First you'll need a git repository to store your cluster desired state. | ||
In our example we are going to use [`fluxcd/flux-get-started`](https://github.com/fluxcd/flux-get-started). | ||
If you want to use that too, be sure to create a fork of it on GitHub. | ||
|
||
Create a directory and add the `flux` namespace definition to it: | ||
|
||
```sh | ||
mkdir fluxcd | ||
|
||
cat > fluxcd/namespace.yaml <<EOF | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: flux | ||
EOF | ||
``` | ||
|
||
Create a kustomization file and use the Flux deploy YAMLs as base: | ||
|
||
```sh | ||
cat > fluxcd/kustomization.yaml <<EOF | ||
namespace: flux | ||
bases: | ||
- github.com/fluxcd/flux//deploy | ||
patchesStrategicMerge: | ||
- patch.yaml | ||
EOF | ||
``` | ||
|
||
> **Note:** If you want to install a specific Flux release, | ||
> add the version number to the base URL: | ||
> `github.com/fluxcd/flux//deploy?ref=v1.14.0` | ||
|
||
Create a patch file for Flux deployment and set the `--git-url` | ||
parameter to point to the config repository | ||
(replace `YOURUSER` with your GitHub username): | ||
|
||
```sh | ||
export GHUSER="YOURUSER" | ||
cat > fluxcd/patch.yaml <<EOF | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: flux | ||
spec: | ||
template: | ||
spec: | ||
containers: | ||
- name: flux | ||
args: | ||
- --manifest-generation=true | ||
- --memcached-hostname=memcached.flux | ||
- --memcached-service= | ||
- --ssh-keygen-dir=/var/fluxd/keygen | ||
- --git-branch=master | ||
- --git-path=namespaces,workloads | ||
- --git-user=${GHUSER} | ||
- --git-email=${GHUSER}@users.noreply.github.com | ||
- --git-url=git@github.com:${GHUSER}/flux-get-started | ||
EOF | ||
``` | ||
|
||
We set `--git-path=namespaces,workloads` to exclude Helm manifests. | ||
If you want to get started with Helm, please refer to the | ||
["Get started with Flux using Helm"](get-started-helm.md) tutorial. | ||
|
||
## Install Flux with Kustomize | ||
|
||
In the next step, deploy Flux to the cluster (you'll need kubectl **1.14** or newer): | ||
|
||
```sh | ||
kubectl apply -k fluxcd | ||
``` | ||
|
||
Wait for Flux to start: | ||
|
||
```sh | ||
kubectl -n flux rollout status deployment/flux | ||
``` | ||
|
||
## Setup GitHub write access | ||
|
||
At startup Flux generates a SSH key and logs the public key. Find | ||
the SSH public key by installing [fluxctl](../references/fluxctl.md) and | ||
running: | ||
|
||
```sh | ||
fluxctl identity | ||
``` | ||
|
||
In order to sync your cluster state with git you need to copy the | ||
public key and create a deploy key with write access on your GitHub | ||
repository. | ||
|
||
Open GitHub, navigate to your fork, go to **Setting > Deploy keys**, | ||
click on **Add deploy key**, give it a `Title`, check **Allow write | ||
access**, paste the Flux public key and click **Add key**. See the | ||
[GitHub docs](https://developer.github.com/v3/guides/managing-deploy-keys/#deploy-keys) | ||
for more info on how to manage deploy keys. | ||
|
||
## Committing a small change | ||
|
||
In this example we'll be making a configuration change to a web application | ||
and display a different message in the UI. | ||
|
||
Replace `YOURUSER` in | ||
`https://github.com/YOURUSER/flux-get-started/blob/master/workloads/podinfo-dep.yaml` | ||
with your GitHub ID), open the URL in your browser, edit the file, | ||
change the `PODINFO_UI_MESSAGE` env var to `Welcome to Flux` and commit the file. | ||
|
||
By default, Flux git pull frequency is set to 5 minutes. | ||
You can tell Flux to sync the changes immediately with: | ||
|
||
```sh | ||
fluxctl sync | ||
``` | ||
|
||
## Confirm the change landed | ||
|
||
To access our webservice and check out its welcome message, simply | ||
run: | ||
|
||
```sh | ||
kubectl -n demo port-forward deployment/podinfo 9898:9898 & | ||
curl localhost:9898 | ||
``` | ||
|
||
Notice the updated `message` value in the JSON reply. | ||
|
||
## Conclusion | ||
|
||
As you can see, the actual steps to set up Flux, get our app | ||
deployed, give Flux access to it and see modifications land are | ||
very straight-forward and are a quite natural work-flow. | ||
|
||
As a next step, you might want to dive deeper into [how to | ||
control Flux](../references/fluxctl.md), or go through our | ||
hands-on tutorial about driving Flux, e.g. | ||
[automations, annotations and locks](driving-flux.md). |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this was already there or is new, but my thought while reading this was "can be tweaked easily how?"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was already there. Let's address it in #2298