8. flux tutorial¶
Like the tutorials in [flux-01] and [flux-02], this sets up a repository for flux and deploys podinfo, but with the following differences:
Repositories are in gitlab
The podinfo repository is private
8.1. Install flux and create a kubernetes cluster¶
Install flux with brew (macOS):
brew install fluxcd/tap/flux
Add flux completion to fish (ref. https://fluxcd.io/docs/cmd/flux_completion_fish/ )
Create a kubernetes cluster (for Digital Ocean ref. https://docs.digitalocean.com/products/kubernetes/how-to/create-clusters/ )
Update kubeconfig to use created cluster (https://docs.digitalocean.com/products/kubernetes/how-to/connect-to-cluster/ )
Check flux pre-req:
> flux check --pre ► checking prerequisites ✔ kubectl 1.21.0 >=1.18.0-0 ✔ Kubernetes 1.21.2 >=1.16.0-0 ✔ prerequisites checks passed
8.2. Bootstrap flux¶
Run flux bootstrap command
> flux bootstrap gitlab \ --ssh-hostname=gitlab.com \ --owner=your_gitlab_user --personal \ --repository=flux-test \ --branch=master \ --path=clusters/my-cluster ► connecting to https://gitlab.com ... ✔ all components are healthy
8.3. Deploy podinfo (from a private repo)¶
Fork podinfo to a private repo (e.g., https://gitlab.com/your_gitlab_user/podinfo)
Clone bootstrapped flux repository
Create source git repository manifest for podinfo
flux-test (master)> flux create source git podinfo \ --url=https://gitlab.com/your_gitlab_user/podinfo \ --branch=master \ --interval=30s \ --export > ./clusters/my-cluster/podinfo-source.yaml
Because the podinfo repo is private, fix the url and add a secretRef in the GitRepository manifest: From:
--- apiVersion: source.toolkit.fluxcd.io/v1beta1 kind: GitRepository metadata: name: podinfo namespace: flux-system spec: interval: 30s ref: branch: master url: https://gitlab.com/your_gitlab_user/podinfo
To:
--- apiVersion: source.toolkit.fluxcd.io/v1beta1 kind: GitRepository metadata: name: podinfo namespace: flux-system spec: interval: 30s ref: branch: master url: ssh://git@gitlab.com/your_gitlab_user/podinfo secretRef: name: flux-system
Create kustomization for podinfo
flux-test (master)> flux create kustomization podinfo \ --source=podinfo \ --path="./kustomize" \ --prune=true \ --validation=client \ --interval=5m \ --export > ./clusters/my-cluster/podinfo-kustomization.yaml
Commit and push
Check flux logs and get kustomizations
> flux logs --kind=Kustomization --name=podinfo > flux get kustomizations
Forward port to access the application
> kubectl get deployments,svc NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/podinfo 2/2 2 2 5m25s NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/kubernetes ClusterIP 10.245.0.1 <none> 443/TCP 3d service/podinfo ClusterIP 10.245.150.90 <none> 9898/TCP,9999/TCP 5m25s > kubectl port-forward service/podinfo :9898 Forwarding from 127.0.0.1:65326 -> 9898 Forwarding from [::1]:65326 -> 9898
Access port with a web browser http://localhost:65326
8.4. References¶
Get Started with Flux (fluxcd.io) (Retrieved 2021-07-29)