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

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