Helm¶
You must have Helm 3.0 installed for this functionality to work.
Helm is an automation tool for creating all the Kubernetes resources needed to deploy a single application. This is done by creating a “Chart” that describes the components of your installation. When a chart is instantiated, a “Release” is created.
The helm_install() function makes some assumptions about the environment. Values for charts are placed in a subdirectory name charts/. If you don’t provide a release_name, it is derived from the last word in the chart_name. For example, if the chart_name is “stable/tomcat”, “tomcat” is the release name.
Finally, the YAML file with modified values are stored using the following naming pattern: charts/{{release_name}}-values.yaml
A directory structure would look like this:
my-project/
charts/
tomcat-values.yaml
deploy.py
Let’s say the only thing we want to modify on the Tomcat chart was ingress information. The contents of tomcat-values.yaml would look like this:
ingress:
enabled: true
hosts:
- tomcat.{{domain}}
tls:
- hosts:
- tomcat.{{domain}}
Note that we are using Jinja2 templating syntax. When we call helm_install, we can provide the value of all template variables in the param parameters.
You can see this in the following example of deploy.py:
from k9.helm import *
form k9.core import set_default_namespace()
// Set the namespace to install into
set_default_namespace('tomcat')
helm_install('stable/tomcat', {'domain': 'sandbox.simoncomputing.com'})
In the above example, what will happen is the charts/tomcat-values.yaml file will be translated using Jinja to another file .output/tomcat-values.yaml. That file will look like this:
ingress:
enabled: true
hosts:
- tomcat.sandbox.simoncomputing.com
tls:
- hosts:
- tomcat.sandbox.simoncomputing.com
From that point the helm command is called like this:
helm install -f .output/tomcat-values.yaml tomcat stable/tomcat
Note that all Helm functions will throw an exception if an error occurs.
- k9.helm.helm_repo_add(repo_name: str, repo_url: str)[source]¶
Adds the repository to the current kubernetes environment.
- Parameters
repo_name – Local name of repository
repo_url – URL of repository
- Returns
output string on success, exception if failure.
- k9.helm.helm_repo_update()[source]¶
Update the local copy of the repository with the current repository.
- Returns
output string on success, exception if failure.
- k9.helm.helm_repo_ls()[source]¶
Lists available repositories.
- Returns
Object derived from JSON output, exception on failure.
- k9.helm.helm_repo_remove(repo_name: str)[source]¶
Removes a repository.
- Parameters
repo_name –
- Returns
output string on success, exception if failure.
- k9.helm.helm_install(chart_name: str, params, release_name: Optional[str] = None, values_path: Optional[str] = None, debug=False, namespace: Optional[str] = None)[source]¶
Runs the Helm installation for the specified chart. Before the chart is installed, the values file which should have the same name as the release_name will be evaluated with Jinja, using the parameters to build the new values file.
The values file is written to the .output/{{release-name}}-values.yaml.
Helm installation is run with this ‘values.yaml’ file and on the default namespace set using set_default_namespace()
- Parameters
chart_name – Name of Chart.
params – Parameter values in a Dictionary used when pre-processing values. If it is not a dictionary, the vars() function is run on the object to create a dictionary.
release_name – If None - release_name is defaulted to the last word in chart_name. For example if chart_name is “stable/tomcat”, the release_name is “tomcat”. Release name is also used to construct the charts values file in the following format: ./charts/{{release_name}}-values.yaml
values_path – Override values file location
debug – If True, runs Helm with –debug and –dry-run, which will not actually run and displays the chart values. Default is False.
namespace – Namespace to install the chart on. If None, we use the default namespace.
- Returns
output string on success, exception if failure.
- k9.helm.helm_uninstall(release_name: str, namespace: Optional[str] = None)[source]¶
Uninstalls the specified release.
- Parameters
release_name – Name of the release you want to uninstall.
namespace – Namespace to uninstall the chart from. If None, we use the default namespace.
- Returns
Returns output value from uninstall process. Otherwise, throws exception.
- k9.helm.helm_ls(namespace: Optional[str] = None)[source]¶
Lists all current helm installations.
- Parameters
namespace – Namespace to list charts from. If None, we use the default namespace.
- Returns
List of all helm installations. Throws exception on error.
Sample Output:
[ {"name":"tomcat", "namespace":"default", "revision":"1", "updated":"2019-12-10 18:28:43.753814 -0500 EST", "status":"deployed", "chart":"tomcat-0.4.0", "app_version":"7.0"} ]