Skip to content

Helm Chart Helper

⚠ THIS REPO IS WIP. USE AT YOUR OWN RISK!

The following functions are included:

HELPERS:

  • Creating namespaces
  • Creating docker-registry secrets
  • Creating secrets
  • Creating ingress
  • Creating tls-secrets
  • Creating configMaps
  • Creating serviceMonitor to work with prometheus metrics
  • Creating job

CHART:

  • Creating a chart which includes the following "modified" helpers:
  • chart.secrets
  • chart.configMaps
  • chart.serviceMonitor

You can also create jobsand sidecars in CHART

Package Registry URL


add ohMyHelm as dependency

Create an empty Chart.yaml and enter the following:

apiVersion: v2
name: yourchartname
description: Example Chart with ohmyhelm as dependencie
type: application
version: 0.1.0
appVersion: "1.16.0"

dependencies:
  - name: ohmyhelm
    alias: nodered
    repository: https://gitlab.com/api/v4/projects/28993678/packages/helm/stable
    version: 1.2.0
    condition: nodered.enabled
  - name: ohmyhelm
    alias: secretexample
    repository: https://gitlab.com/api/v4/projects/28993678/packages/helm/stable
    version: 1.2.0
    condition: secretexample.enabled

Now create an values.yaml with the follwing:

nodered:
  enabled: true
  chart:
    enabled: true
    statefulset: true
    fullnameOverride: "nodered"
    container:
      image: nodered/node-red:latest
      ports:
        - name: http
          containerPort: 1880
          protocol: TCP
    statefulsetVolume:
      volumeMounts:
        - name: data-nodered
          mountPath: /data 
      volumeClaimTemplates:
        - metadata:
            name: "data-nodered"
          spec:
            accessModes: 
              - ReadWriteOnce
            # storageClassName: ""
            resources:
              requests:
                storage: 2Gi
secretexample:
  enabled: true
  secrets:
    - name: some-secrets
      namespace: default
      values:
        password:
        user: "example"

install an Chart with ohMyHelm from terminal

The default ohMyHelm doesn't create an deployment, you need to add your values with -f omh-values.yaml to deploy something.

See examples directory in this repository:

  • examples/omh-nodered-deployment-values.yaml
  • examples/omh-nodered-statful-values.yaml
helm repo add ohmyhelm https://gitlab.com/api/v4/projects/28993678/packages/helm/stable
helm repo update
helm install -f omh-values.yaml nodered ohmyhelm/ohmyhelm  --version 1.1.0

Need more information, see: docs - helm install


HELPERS

namespaces

To add a namespace to namespaces add the following to values.yaml:

namespaces:
  setPreInstallHook: true
  spaces:
    - name: monitoring

The value setPreInstallHook should set always "true". So, the namespace will set bevore other objects are created.

Please Note: a namespace that was created with Hook will never removed when you helm uninstall <releaseName> your release.

You can add multiple values too.

namespaces:
  setPreInstallHook: true
  spaces:
    - name: monitoring
    - name: mywebapplication
    - name: debugtools

docker-registry

To add a docker-registry secret add the following to values.yaml:

imageCredentials:
  - name: acr-registry
    namespace: mywebapplication
    registry: https://ohmyhelm.azure.com
    username: "012345-678901-23456789-0090-22222"
    accessToken: "thisIsMySecretToken-DONTSHAREIT"

You can add multiple values too.

imageCredentials:
  - name: acr-registry
    namespace: mywebapplication
    registry: https://ohmyhelm.azure.com
    username: "012345-678901-23456789-0090-22222"
    accessToken: "thisIsMySecretToken-DONTSHAREIT"
  - name: docker-registry
    namespace: mywebapplication
    registry: https://index.docker.io/v1/
    username: "yourUsername"
    accessToken: "yourPassword-or-Token-here"

ingress

To add an ingress add the following to values.yaml. The following entry create a single ingress with.

ingress: {}
  # - name: myspecialingress
  #   namespace: default
  #   annotations: 
  #     nginx.ingress.kubernetes.io/rewrite-target: /
  #   tls:
  #       - secretName: secret-tls
  #         hosts:
  #           - chart-example.local
  #   hosts:
  #     - host: chart-example.local
  #       http:
  #         paths:
  #         - path: /
  #           backend:
  #             serviceName: your-service-name-here
  #             servicePort: http

secrets

To add a secret to secrets add the following to values.yaml. The following entry create a single secret with a pre defined password.

secrets:
  - name: yourDb-credentials
    namespace: debugtools
    values:
      password: "thisIsSecret"
      user: "example"

You can add multiple secrets too. If you leave an value empty a random value will be generated. Multiple keys in values are also supported.

secrets:
  - name: yourDb-credentials
    namespace: debugtools
    values:
      password: "thisIsSecret"
      user: "example"
  - name: yourOther-credentials
    namespace: mywebapplication
    values:
      masterPassword: 
      masterUser: "kyloRun"
      masterToken:
      readOnlyPassword: "1234"
      readOnlyUser: "rouser"
      readOnlytoken: "12345-3343554-33456543"

tls-secrets

To add a tls to tls-secrets add the following to values.yaml. The following entry creates one or multiple tls-secret.

tls-secrets:
  - name: secret-tls
    values:
      tls.crt: |
        MIIC2DCCAcCgAwIBAgIBATANBgkqh ...
      tls.key: |
        MIIEpgIBAAKCAQEA7yn3bRHQ5FHMQ ...
  - name: example2-com-tls
    values:
      tls.crt: |
        MIIC2DCCAcCgAwIBAgIBATANBgkqh ...
      tls.key: |
        MIIEpgIBAAKCAQEA7yn3bRHQ5FHMQ ...

configMaps

To add a configMap to configs add the following to values.yaml.

configs:
  - name: yourWeb-config
    namespace: mywebapplication
    dontOverrideOnUpdate: false
    values:
      config.yaml: |
        server:
          host: localhost
          port: 8080
        name: first-order
  - name: yourApp-config
    namespace: mywebapplication
    dontOverrideOnUpdate: true
    values:
      publicKey: thisIsMyPublicKey77838884774736627736 
      appURL: "mywebapp.local"
      masterLogin: "enabled"
      rouserLogin: "enabled"
      inDevelopmentMode: "true"

With the option dontOverrideOnUpdate: true you can set that an helm upgrade <releaseName> will not overwrite your config. You can add multiple configMaps in configs.

serviceMonitor

To add a serviceMonitor to monitoring add the following to values.yaml.

monitoring:
  - name: yourWebApplication
    namespace: monitoring
    release: prometheus
    endpoints:
      - port: metrics
        interval: 15s
        path: merics
        scheme: http
      - port: metrics-init
        interval: 60s
  - name: yourService
    namespace: monitoring
    release: prometheus
    endpoints:
      - port: metrics-init
        interval: 60s
  ```

> You can add multiple serviceMonitor to `monitoring`.
>
> In this example the key `name` with value `yourWebApplication` will automatically changed to `yourWebApplication-metrics`.
>
> For the `selector` `app.kubernetes.io/name` the key `name` will be used without the praefix. This value must match the service you want to select.
>
> For each `serviceMonitor` you can add multiple `endpoints`. `endpoints` requires `port` and `interval`. `path` and `scheme` are optional.

---

## `CHART`

Enable the `CHART` function by changing the value `chart.enabled` to `true`

```yaml
chart:
  enabled: true
  ...

statefulset or deployment

You can switch between statefulset and deployment by changing the follwing value statefulset to true or false.

chart:
  ...
  statefulset: true

Depending on your choice, you need to modify your values in statefulsetVolume or deploymentVolume.

chart:
  ...
  # if statefulset: true
  statefulsetVolume:
    volumeMounts:
      - name: foo
        ...
    volumeClaimTemplates:
      - name: bar
        ...
    volumes:
      - name: foo2
        ...
  # if statefulset: false        
  deploymentVolume:
    volumeMounts:
      - name: foo
        ...
    volumes:
      - name: foo2
        ...        

Environments

you can add environments by setting it here:

charts:
  containers:
    env: []
    #   - name: foo
    #     value: bar
    staticEnv: []
    #   - name: foo
    #     value: bar
    extraEnv: []
    #   - name: foo
    #     value: bar
  initContainers:
    env: []
    #   - name: foo
    #     value: bar
    staticEnv: []
    #   - name: foo
    #     value: bar
    extraEnv: []
    #   - name: foo
    #     value: bar
  job:
    env: []
    #   - name: foo
    #     value: bar
    staticEnv: []
    #   - name: foo
    #     value: bar
    extraEnv: []
    #   - name: foo
    #     value: bar
  initContainer:

initContainer and Jobs

You can add an initContainer and an job. By default, the initContainer waits that the job has completed. After that, the initContainer stops and the container starts.

If you need the same image as in the charts.container.image section, leave charts.job.image value empty.

  initContainer:
    enabled: true

  job:
    enabled: false

RBAC

You can add roles and rolebindings by enabling the rbac

  rbac:
    enabled: false

app label

you can enabling applabel to create the following labels:

app=<yourservicename>

  applabel: true

Included helpers in chart

In CHART you CAN'T set an individually namespace for chart.secrets or chart.configMaps. It will use the namespace, you set with helm install --namespace "mynamespace". If you want to create secrets or configMaps use the HELPERS instead.

chart:
  ...
  # ohMyHelm - secret helper
  secrets:
    - name: secret-nodered
      values:
        user: foo
        pass: bar

  # ohMyHelm - config helper
  configs:
    - name: config-nodered
      dontOverrideOnUpdate: false
      values:
        values.yaml: |
          server:
            host: localhost
            port: 80
          name: my-first-db

  # ohMyHelm - prometheus monitoring
  monitoring:
    - name: yourservice
      namespace: monitoring
      release: prometheus
      endpoints:
        - port: http
          interval: 15s
          path: merics
          scheme: http

Last update: November 6, 2021