Leader chart

Assuming that you already went through the chart per service approach, you should use leader chart approach with Helm charts for many microservices when you want:

  • to avoid unnecessary duplication

  • to have consistency accross changes

  • to introduce global changes in an easy manner.

You should be aware that this approach depends on the amount of charts for each lead chart and can introduce:

  • high complexity of templates

  • tight coupling

  • less flexible local changes.

Goal of this section: deploy the microservice together with its database using Helm charts.

Leader Helm chart setup

Make sure that you are under root folder of the clone repository and run:

helm create leader

You should now have the following structure:

leader
├── Chart.yaml
├── charts
├── templates
│   ├── NOTES.txt
│   ├── _helpers.tpl
│   ├── deployment.yaml
│   ├── hpa.yaml
│   ├── ingress.yaml
│   ├── service.yaml
│   ├── serviceaccount.yaml
│   └── tests
│       └── test-connection.yaml
└── values.yaml

Remove the templates folder under leader because in this approach we will not use it.

Modify Chart.yaml

Because we will deploy both charts (faq and database), the Chart.yaml file needs to be modified and specify the database dependency there.

Go to Chart.yaml and add a new section regarding dependencies.

# These are the dependencies needed by the leader chart.
# Each time you need a new dependency, add it in this area
dependencies:
  - name: postgresql
    version: 12.1.2
    repository: "https://charts.bitnami.com/bitnami"

Save your work and run in the terminal the following command in order to update dependencies:

cd leader
helm dependency update

This command installs PostgreSQL Helm Chart package in the charts directory:

ls charts
postgresql-12.1.2.tgz

Modify values.yaml file

Go to the newly created charts and find the values.yaml file. You can use vim or your favorite IDE to edit its values. There you need to configure the PostgreSQL chart with the required parameters as we did in Basics section. In that case, we set the parameters from command line, now we’ll set them using the values.yaml file.

Delete everything from your values.yaml and just add the following:

  • Minikube

  • OpenShift

postgresql:
  auth:
      username: faq-default
      password: postgres
      database: faq
  primary:
    persistence:
      enabled: false
postgresql:
  auth:
      username: faq-default
      password: postgres
      database: faq
  primary:
    podSecurityContext:
      enabled: false
    persistence:
      enabled: false
    containerSecurityContext:
      enabled: false

Notice that global prefix is not required.

Save your work.

Assembling subcharts in charts folder

If you went through chart per service setup you will reuse the chart created there.

Copy the content of faq chart from to your leader/charts folder. The resulted leader folder should look like this:

leader
├── Chart.yaml
├── charts
│   └── faq
│       ├── Chart.yaml
│       ├── charts
│       ├── templates
│       │   ├── NOTES.txt
│       │   ├── _helpers.tpl
│       │   ├── configmap.yaml
│       │   ├── deployment.yaml
│       │   ├── hpa.yaml
│       │   ├── ingress.yaml
│       │   ├── service.yaml
│       │   ├── serviceaccount.yaml
│       │   └── tests
│       │       └── test-connection.yaml
│       └── values.yaml
└── values.yaml

Go to leader/charts/faq/values.yaml and update the PostgreSQL properties:

postgresql:
  server: leader-postgresql
  postgresqlUsername: faq-default
  secretName: leader-postgresql
  secretKey: password

Deploy the leader charts

Install your charts by using:

$ helm install leader ./leader
$ helm status leader

You can validate the installation via:

helm list
helm get all leader

If you worked locally, please run the following commands:

export APP=$(minikube service leader-faq --url -n dev)
curl '$APP/ask/CEE' -H 'accept: application/json'

Congratulations, you have installed the application with just one command!