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 Install flux and create a kubernetes cluster -------------------------------------------- - Install flux with brew (macOS): .. code-block:: fish 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: .. code-block:: fish > flux check --pre ► checking prerequisites ✔ kubectl 1.21.0 >=1.18.0-0 ✔ Kubernetes 1.21.2 >=1.16.0-0 ✔ prerequisites checks passed Bootstrap flux -------------- - Run flux bootstrap command .. code-block:: fish > 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 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 .. code-block:: fish 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: .. code-block:: yaml --- 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: .. code-block:: yaml --- 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 .. code-block:: fish 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 .. code-block:: fish > flux logs --kind=Kustomization --name=podinfo > flux get kustomizations - Forward port to access the application .. code-block:: fish > 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 443/TCP 3d service/podinfo ClusterIP 10.245.150.90 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 References ---------- .. [flux-01] `Get Started with Flux (fluxcd.io) `_ (Retrieved 2021-07-29) .. [flux-02] `How To Set Up a Continuous Delivery Pipeline with Flux on DigitalOcean Kubernetes (digitalocean.com) `_ (Retrieved 2021-07-29)