Skip to main content

Helm interface in cdk8s

Project description

Github PyPI

Why

I still have two fundamental problems with using helm now that tiller is gone. The first is that it sometimes requires you to put secrets in config files. There's no good universal way to specify my manifests with shared secrets without having them show up in my repositories. The second is that there's no good way to manage global variables within a massive project. Sure it's possible with subcharts, but I've found it gets really messy really quickly.

I like using cdk8s for my own images and deployments. I think it's clean and easy way to follow best practices, and with the help of jedi and autocompletion it's super easy to write things that you know will work right.

Installing

pipenv install cdhelm to add cdhelm to your Pipfile.

from cdhelm import Helm in your cdk8s file.

Workflow

This library allows you to specify a helm chart within cdk8s. It's pretty flexible with how it lets you organize your project.

You can define a Helm object like so:

prometheus = Helm(
    name="prometheus",
    repo="https://kubernetes-charts.storage.googleapis.com",
    chart="prometheus",
    version="11.12.0",
    namespace="monitoring,
    path=".charts",
)

namespace defaults to default and path defaults to .charts. Otherwise everything else is required. version is explicitly required because I can't think of a reason you should ever rely on latest implicitly.

This returns a Helm object that you can interact with. Creating the object pulls the chart to path and populates object.values with the default values file. The is currently no option to not pull the whole chart.

Adding values

You can specify new values either through a values file like with normal helm charts.

prometheus.updateFile("configs/prometheus.yaml")

Or you can specify new values through a python dictionary corrisponding to the values file.

prometheus_conf = {
    "alertmanager": {
        "baseURL": "https://alert." + mydomain
    },
    "server": {
        "baseURL": "https://prom." + mydomain
    },
}
prometheus.update(prometheus_conf)

Both actions only update exactly what is specified so it's possible to use both together even on variables within the same scope.

Extracting values or working entirely within cdk8s

It is possible to create a cdk8s chart from the Helm object. This chart will bake in the current values. Please update your values before returning a chart.

monitoring_app = App(outdir=dist + "monitoring")
prometheus_chart = prometheus.Chart(monitoring_app, "prometheus")

You can use this to pass along information from the chart such as services and ports to other parts of your code. This is a good way to interface different parts of your server without hardcoding values. You may synth the app the chart is a part of and work with helm as though it's just another part of your cdk8s implementation. Every part of the chart will be rendered out using helm template.

monitoring_app.synth()

Working outside of cdk8s

It is also possible to keep the benefits of having helm specified in your cdk8s code while still letting helm do its thing. You can have cdk8s write out a values.yaml file so you can manage helm manually. render() will overwrite the default rendered values path.

prometheus.render("helm/myvalues.yaml")

Or you can have cdk8s render out a helper script to the specified folder to work with exactly the version and values you already specified.

prometheus.write_controls("_charts")

The rendered script should work with any helm command that works with a specific chart. Use -h with the chart to see a help printout.

All commands will be given the following options when applicable:
  --namespace monitoring
  --repo https://kubernetes-charts.storage.googleapis.com
  --version 11.12.0
  --values /home/myhome/myproject/.charts/prometheus-11.12.0/prometheus/rendered-values.yaml
  [NAME] => prometheus
  [CHART] => prometheus
  [RELEASE] => prometheus

All other given options will be appended
Use -h as an appended option for any helm command

Available Helm commands:
  help
  history
  install
  rollback
  show all
  show chart
  show readme
  show values
  status
  template
  test
  uninstall
  upgrade

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cdhelm-0.1.4.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

cdhelm-0.1.4-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file cdhelm-0.1.4.tar.gz.

File metadata

  • Download URL: cdhelm-0.1.4.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for cdhelm-0.1.4.tar.gz
Algorithm Hash digest
SHA256 8d72d8180baa6baed1b3b888ba2d8500f55ed93031c7a23cbd9cb560aaf837bc
MD5 704bf4eba843fb0ef3981259dda3a3d4
BLAKE2b-256 a14e8da08acd1a51806b4295cfdeec23e81c974d43dff0e79e753d3dd573b2c2

See more details on using hashes here.

Provenance

File details

Details for the file cdhelm-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: cdhelm-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for cdhelm-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 0e495feb20c34eb8b3f78068037eab261e2bc155402c8cf23fc9f62f5201749b
MD5 1d9927b2b8e0cc61a5de78d4b3c9f655
BLAKE2b-256 3f4743f9fca98da5066580a20c9be9b71e31ec696fa13d4a9caa317ac1f29206

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page