Introduction

Kubecoins is a sample that is use to demonstrate aspects of building,deploying and operating a microservice application that runs on Kubernetes and is deployed via GitOps.

Demos

This section will contain walkthroughs for specific demos.

Flux2

Demo: Flux2 Health Checks & Dependencies

This demo is used to show the following features of Flux2:

  • Health Checks
  • Dependencies

The key takeaways of this demo are to show that these 2 features can be used to ensure that services are started in order in a predictable way.

Setup

  1. Fork the flux-nonprod-clusters repo.

  2. Create a GitHub Personal Access Token (pat) with the repo scope.

  3. Set the following environment variables:

export GITHUB_TOKEN=<your-pat>
export GITHUB_USER=<your-username>
  1. Ensure the apps/dev/backend-values.yaml file contains the following and this is committed and pushed to your form:
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
  name: backend
  namespace: podinfo
spec:
  chart:
    spec:
      version: ">=1.0.0-alpha"
  test:
    enable: true
  values:
    faults:
      testFail: true

This ensures the Helm tests are run and that the tests fail

Demo Script

  1. Open the cloned repo in VSCode or your favourite editor.

  2. Open the following files and point out the import aspects which include (not exhaustive list):

    • apps/base/podinfo/backend.yaml - the HelmRepository ref for the chart source and also that its going to act a gRPC server.
    • apps/base/podinfo/frontend.yaml - that this service dependsOn the backend service and that it contains the URL for communicating with the backend service.
    • apps/dev/backend-values.yaml - helm tests are enabled and set to fail. Also the chart version.
    • clusters/dev/app1-podinfo.yaml - it uses the kustomization from ./apps/dev and dependsOn the infrastructure. There is also a Health Check defined that will be used to determine if to report Ready. The health check will use the frontend HelmRelease.

At this stage explain that we now have a dependency chain: infrastructure<-Kustomization(app-podinfo)<-HelmRelease(frontend)<-HelmRelease(backend)

  1. Open 2 terminal windows (or terminal panes)

The following steps will refer to a terminal window/pane using the following (term1) or (term2) and this window pane should be used.

  1. (term1) Create a cluster to represent the dev environment using kind:
kind create cluster --name=kubecoins-dev
  1. (term1) Check that Flux2 pre-reqs are met:
flux check --pre
  1. (term2) Start k9s and show all pods

  2. (term1) Bootstrap Flux2 using your cloned repo:

flux bootstrap github \
    --context=kind-kubecoins-dev \
    --owner=${GITHUB_USER} \
    --repository=flux-nonprod-clusters \
    --branch=main \
    --personal \
    --path=clusters/dev
  1. (term2) Watch Flux2 controllers start up and wait until they are running.

Explain about the Flux2 bootstrap process if needed

  1. (term2) Watch the infrastructure (nginx/redis) pods start up and wait until they are running.

  2. (term2) Point out that the backned-podinfo pod is running but the backend-podinfo-fault-test pods have failed (these are the pods from the Helm test):

backend pods

  1. (term2) Change k9s to show the kustomizations.kustomize.toolkit.fluxcd.io instances (hit esq, enter crds, select the kustomizations crd):

kustomization not ready

Explain that the kustomization isn’t ready as its health check isn’t passing and thats because the frontend HelmRelease isn’t ready.

  1. (term2) Change k9s to show the helmrelease.kustomize.toolkit.fluxcd.io instances (hit esq, select the helmreleases crd):

helmreleases not ready

Explain why the two HelmRelease for podinfo aren’t ready. The backend isn’t ready even though the pod is running as the helm test failed. And the frontend isn’t ready as its dependency isn’t ready.

  1. We will now fix the solution. In your editor change apps/dev/backend-values.yaml so it is the same as this:
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
  name: backend
  namespace: podinfo
spec:
  chart:
    spec:
      version: ">=1.0.0-alpha"
  test:
    enable: false
  1. (term1) Add, commit and push this change

  2. (term2) In k9s watch the HelmReleases change state to Ready.

helmreleases ready

Explain the first backend is ready as Helm test is no longer failing which means that frontend‘s dependencies are met and it can them be applied and will become ready.

  1. (term2) Change k9s to show the kustomizations.kustomize.toolkit.fluxcd.io instances (hit esq, select the kustomizations crd):

kustomization ready

Explain that the kustomization is now Ready because the Health Check which is passing. The health check is on the frontend HelmRelease.

  1. (term2) Changes k9s to show all the pods (enter :, enter pods):

pods running