Add generated manifests to get started guide

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
pull/675/head
Stefan Prodan 4 years ago
parent 0aeb3128ed
commit dcb505045e
No known key found for this signature in database
GPG Key ID: 3299AEB0E4085BAF

@ -2,17 +2,21 @@
!!! note "Basic knowledge"
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).
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.
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 your Kubernetes clusters.
## Prerequisites
In order to follow the guide, you will need one Kubernetes cluster version 1.16 or newer and kubectl version 1.18.
In order to follow the guide, you will need a 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.
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
Flux is installed in a GitOps way and its manifest will be pushed to the repository,
so you will also need a GitHub account and 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 (check all permissions under `repo`) to enable Flux do this.
@ -64,7 +68,7 @@ Create the cluster using Kubernetes kind or set the kubectl context to an existi
```sh
kind create cluster
kubectl cluster-info --context kind-kind
kubectl cluster-info
```
Verify that your staging cluster satisfies the prerequisites with:
@ -94,7 +98,8 @@ flux bootstrap github \
and `--arch=arm64` for ARMv8 64-bit container images.
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.
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:
@ -112,7 +117,7 @@ flux bootstrap github \
Example output:
```console
$ flux bootstrap github --owner=gitopsrun --repository=fleet-infra --path=staging-cluster --team=devs
$ flux bootstrap github --owner=gitopsrun --team=devs --repository=fleet-infra --path=./clusters/my-cluster
► connecting to github.com
✔ repository created
✔ devs team access granted
@ -134,7 +139,8 @@ deployment "notification-controller" successfully rolled out
✔ bootstrap finished
```
If you prefer GitLab, export `GITLAB_TOKEN` env var and use the command [flux bootstrap gitlab](../cmd/flux_bootstrap_gitlab.md).
If you prefer GitLab, export `GITLAB_TOKEN` env var and
use the command [flux bootstrap gitlab](../guides/installation.md#gitlab-and-gitlab-enterprise).
!!! hint "Idempotency"
It is safe to run the bootstrap command as many times as you want.
@ -145,21 +151,25 @@ If you prefer GitLab, export `GITLAB_TOKEN` env var and use the command [flux bo
## 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 :).
We are going to drive app deployments in a GitOps manner,
using the Git repository as the desired state for our cluster.
Instead of applying the manifests directly to the cluster,
Flux will apply it for us instead.
Therefore, we need to clone the repository to our local machine.
Therefore, we need to clone the repository to our local machine:
```sh
git clone https://github.com/$GITHUB_USER/fleet-infra
cd fleet-infra
```
## 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.
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.
Create a [GitRepository](../components/source/gitrepositories/)
manifest pointing to podinfo repository's master branch:
```sh
flux create source git podinfo \
@ -169,16 +179,33 @@ flux create source git podinfo \
--export > ./clusters/my-cluster/podinfo-source.yaml
```
Commit and push it to the `fleet-infra` repository, then Flux applies it to the cluster.
The above command generates the following manifest:
```yaml
apiVersion: source.toolkit.fluxcd.io/v1beta1
kind: GitRepository
metadata:
name: podinfo
namespace: flux-system
spec:
interval: 30s
ref:
branch: master
url: https://github.com/stefanprodan/podinfo
```
Commit and push it to the `fleet-infra` repository:
```sh
git add -A && git commit -m "Adds podinfo git source"
git add -A && git commit -m "Add podinfo GitRepository"
git push
```
## Deploy podinfo application
We will create a kustomization manifest for podinfo. This will apply the manifest in the `kustomize` directory in the podinfo repository.
We will create a Flux [Kustomization](../components/kustomize/kustomization/) manifest for podinfo.
This configures Flux to build and apply the [kustomize](https://github.com/stefanprodan/podinfo/tree/master/kustomize)
directory located in the podinfo repository.
```sh
flux create kustomization podinfo \
@ -190,27 +217,45 @@ flux create kustomization podinfo \
--export > ./clusters/my-cluster/podinfo-kustomization.yaml
```
Commit and push the kustomization manifest to the git repository so that Flux applies it to the cluster.
The above command generates the following manifest:
```yaml
apiVersion: kustomize.toolkit.fluxcd.io/v1beta1
kind: Kustomization
metadata:
name: podinfo
namespace: flux-system
spec:
interval: 5m0s
path: ./kustomize
prune: true
sourceRef:
kind: GitRepository
name: podinfo
validation: client
```
Commit and push the `Kustomization` manifest to the repository:
```sh
git add -A && git commit -m "Adds podinfo kustomization"
git add -A && git commit -m "Add podinfo Kustomization"
git push
```
The structure of your repository should look like this:
```
fleet-infra
└── clusters/
└── my-cluster/
├── flux-system/
│ ├── gotk-components.yaml/
│ ├── gotk-sync.yaml/
│ └── kustomization.yaml/
│ ├── gotk-components.yaml
│ ├── gotk-sync.yaml
│ └── kustomization.yaml
├── podinfo-kustomization.yaml
└── podinfo-source.yaml
```
## Watch Flux sync the application
In about 30s the synchronization should start:
@ -218,11 +263,11 @@ In about 30s the synchronization should start:
```console
$ watch flux get kustomizations
NAME READY MESSAGE
flux-system main/fc07af652d3168be329539b30a4c3943a7d12dd8 False True Applied revision: main/fc07af652d3168be329539b30a4c3943a7d12dd8
podinfo master/855f7724be13f6146f61a893851522837ad5b634 False True Applied revision: master/855f7724be13f6146f61a893851522837ad5b634
flux-system True Applied revision: main/fc07af652d3168be329539b30a4c3943a7d12dd8
podinfo True Applied revision: master/855f7724be13f6146f61a893851522837ad5b634
```
When the synchronization finishes you can check that the podinfo has been deployed on your cluster:
When the synchronization finishes you can check that podinfo has been deployed on your cluster:
```console
$ kubectl -n default get deployments,services
@ -234,18 +279,15 @@ service/podinfo ClusterIP 10.100.149.126 <none> 9898/TCP,9999/TC
```
!!! tip
From this moment forward, any changes made to the webapp
From this moment forward, any changes made to the podinfo
Kubernetes manifests in the master branch will be synchronised with your cluster.
If a Kubernetes manifest is removed from the webapp repository, the reconciler will remove it from your cluster.
If you delete a kustomization from the cluster, the reconciler will remove all Kubernetes objects that
were previously applied from that kustomization.
If you delete a kustomization from the `fleet-infra` repo, the reconciler will remove all Kubernetes objects that
were previously applied from that kustomization.
If a Kubernetes manifest is removed from the podinfo repository, Flux will remove it from your cluster.
If you delete a `Kustomization` from the fleet-infra repository, Flux will remove all Kubernetes objects that
were previously applied from that `Kustomization`.
If you alter the webapp deployment using `kubectl edit`, the changes will be reverted to match
the state described in git. When dealing with an incident, you can pause the reconciliation of a
If you alter the podinfo deployment using `kubectl edit`, the changes will be reverted to match
the state described in Git. When dealing with an incident, you can pause the reconciliation of a
kustomization with `flux suspend kustomization <name>`. Once the debugging session
is over, you can re-enable the reconciliation with `flux resume kustomization <name>`.

Loading…
Cancel
Save