All Projects → mgoltzsche → khelm

mgoltzsche / khelm

Licence: Apache-2.0 License
A Helm chart templating CLI, kpt function and kustomize plugin

Programming Languages

go
31211 projects - #10 most used programming language
Makefile
30231 projects
shell
77523 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to khelm

charts
Helm charts for creating reproducible and maintainable deployments of Polyaxon with Kubernetes.
Stars: ✭ 32 (-30.43%)
Mutual labels:  helm, k8s, helm-charts, helm-chart
stackstorm-ha
K8s Helm Chart (βeta!) that codifies StackStorm (aka "IFTTT for Ops" https://stackstorm.com/) Highly Availability fleet as a simple to use reproducible infrastructure-as-code app
Stars: ✭ 74 (+60.87%)
Mutual labels:  helm, k8s, helm-charts, helm-chart
charts
Public helm charts
Stars: ✭ 15 (-67.39%)
Mutual labels:  helm, k8s, helm-charts, helm-chart
aks-multi-tenant-agic
This sample shows how to use the Application Gateway Ingress Controller in a multi-tenant AKS cluster to expose multiple instances of the same application, one for each tenant.
Stars: ✭ 27 (-41.3%)
Mutual labels:  helm, helm-charts, helm-chart
charts
☸️ Helm Charts for YOURLS
Stars: ✭ 12 (-73.91%)
Mutual labels:  helm, k8s, helm-charts
K8s
Kubernetes Helm Charts for the ORY ecosystem.
Stars: ✭ 127 (+176.09%)
Mutual labels:  helm, k8s, helm-charts
Awesome Helm
Collaborative list of awesome helm charts and resources. PRs are welcome!
Stars: ✭ 543 (+1080.43%)
Mutual labels:  helm, k8s, helm-charts
helm-charts
Official Helm Chart Repository for InfluxData Applications
Stars: ✭ 133 (+189.13%)
Mutual labels:  helm, k8s, helm-charts
Helm Secrets
Successor of zendesk/helm-secrets - A helm plugin that help manage secrets with Git workflow and store them anywhere
Stars: ✭ 165 (+258.7%)
Mutual labels:  helm, k8s, helm-charts
helm-charts
Source & Repo of https://charts.kubesphere.io/main & https://charts.kubesphere.io/test
Stars: ✭ 85 (+84.78%)
Mutual labels:  helm, helm-charts, helm-chart
k8s-digester
Add digests to container and init container images in Kubernetes pod and pod template specs. Use either as a mutating admission webhook, or as a client-side KRM function with kpt or kustomize.
Stars: ✭ 65 (+41.3%)
Mutual labels:  k8s, kpt, kustomize
Helm-Cheat-Sheet
A cheat sheet for Helm commands.
Stars: ✭ 72 (+56.52%)
Mutual labels:  helm, k8s, helm-charts
Quiz
Example real time quiz application with .NET Core, React, DDD, Event Sourcing, Docker and built-in infrastructure for CI/CD with k8s, jenkins and helm
Stars: ✭ 100 (+117.39%)
Mutual labels:  helm, k8s, helm-charts
Helm Secrets
DEPRECATED A helm plugin that help manage secrets with Git workflow and store them anywhere
Stars: ✭ 1,129 (+2354.35%)
Mutual labels:  helm, k8s, helm-charts
Book k8sInfra
< 컨테이너 인프라 환경 구축을 위한 쿠버네티스/도커 >
Stars: ✭ 176 (+282.61%)
Mutual labels:  helm, k8s, kustomize
Helmsman
Helm Charts as Code
Stars: ✭ 854 (+1756.52%)
Mutual labels:  helm, k8s, helm-charts
Helmfiles
Comprehensive Distribution of Helmfiles for Kubernetes
Stars: ✭ 205 (+345.65%)
Mutual labels:  helm, k8s, helm-charts
k8s-ovpn-chart
[DEPRECATED] Helm chart for a private OpenVPN server
Stars: ✭ 19 (-58.7%)
Mutual labels:  helm, helm-charts, helm-chart
Ingressmonitorcontroller
A Kubernetes controller to watch ingresses and create liveness alerts for your apps/microservices in UptimeRobot, StatusCake, Pingdom, etc. – [✩Star] if you're using it!
Stars: ✭ 306 (+565.22%)
Mutual labels:  helm, k8s, helm-charts
cattlectl
gain control over your ranch
Stars: ✭ 33 (-28.26%)
Mutual labels:  k8s, helm-charts, helm-charts-as-code

khelm GitHub workflow badge Go Report Card

A Helm chart templating CLI, helm to kustomize converter, kpt function and kustomize plugin.

Formerly known as "helm-kustomize-plugin".

Motivation / History

Helm charts provide a great way to share and reuse Kubernetes applications and there is a lot of them. However writing helm templates is cumbersome and you cannot reuse a chart properly if it does not yet support a particular parameter/value.

Kustomize solves these issues declaratively by merging Kubernetes API objects which grants users of a kustomization the freedom to change anything. However kustomize neither supports lifecycle management nor templating with externally passed in values (which is sometimes still required).

To overcome the gap between helm and kustomize initially this repository provided a kustomize plugin and k8spkg was used for lifecycle management.
Since kpt is published helm and kustomize can be run as (chained) kpt functions supporting declarative, GitOps-based workflows. kpt also supports dynamic modification of static (rendered) manifests with externally passed in values using setters as well as dependency and lifecycle management.

Features

  • Templates/renders a Helm chart
  • Builds local charts automatically when templating
  • Automatically fetches and updates required repository index files when needed
  • Allows to automatically reload dependencies when lock file is out of sync
  • Allows to use any repository without registering it in repositories.yaml
  • Allows to exclude certain resources from the Helm chart output
  • Allows to enforce namespace-scoped resources within the template output
  • Allows to enforce a namespace on all resources
  • Allows to convert a chart's output into a kustomization

Supported interfaces

khelm can be used as:

Usage examples can be found in the example and e2e directories.

kpt function

The khelm kpt function templates a chart and returns the output as single manifest file or kustomization directory (when outputPath ends with /). The kustomization output can be used to apply further transformations by running a kustomize function afterwards.

In opposite to the kustomize plugin approach kpt function outputs can be audited reliably when committed to a git repository, a kpt function does not depend on particular plugin binaries on the host and CD pipelines can run without dependencies to rendering technologies and chart servers since they just apply static mainfests (and eventually change values using kpt cfg set) to a cluster using kpt live apply.

kpt function usage example

A kpt function can be declared as annotated ConfigMap within a kpt project. A kpt project can be initialized and used with such a function as follows:

mkdir example-project && cd example-project
kpt pkg init . # Creates the Kptfile
cat - > khelm-function.yaml <<-EOF
  apiVersion: v1
  kind: ConfigMap
  metadata:
    name: cert-manager-manifest-generator
    annotations:
      config.kubernetes.io/function: |
        container:
          image: mgoltzsche/khelm:latest
          network: true
      config.kubernetes.io/local-config: "true"
  data:
    repository: https://charts.jetstack.io
    chart: cert-manager
    version: 0.9.x
    name: my-cert-manager-release
    namespace: cert-manager
    values:
      webhook:
        enabled: false
    outputPath: output-manifest.yaml
EOF
kpt fn run --network . # Renders the chart into output-manifest.yaml

For all available fields see the table below.

Please note that, in case you need to refer to a local chart directory or values file, the source must be mounted to the function using e.g. kpt fn run --mount="type=bind,src=$(pwd),dst=/source,rw=true" ..
An example kpt project and the corresponding e2e test show how to do that.

Kpt can also be leveraged to pull charts from other git repositories into your own repository using the kpt pkg sync . command (with a corresponding dependency set up) before running the khelm function (for this reason the go-getter support has been removed from this project).

If necessary the chart output can be transformed using kustomize. This can be done by declaring the khelm and a kustomize function orderly within a file and specifying the chart output kustomization as input for the kustomize function as shown in the cert-manager example. A more complex example that also manages a Helm chart from another git repository locally as kpt dependency can be found here.

Caching Helm Charts and repository index files

When external Helm Charts are used the download of their repositories' index files and of the charts itself can take a significant amount of time that adds up when running multiple functions or calling a function frequently during development.
To speed this up caching can be enabled by mounting a host directory into the container at /helm, e.g. kpt fn run --mount "type=bind,src=$HOME/.khelm,dst=/helm,rw=true" . as also shown here.
Please be aware that the presence of /helm/repository/repositories.yaml enables a strict repository policy by default (see repository configuration). Therefore, to be independent of existing Helm 2 installations, a host's ~/.helm directory should not be mounted to /helm in most cases.

kustomize exec plugin

khelm can be used as kustomize exec plugin. Though plugin support in kustomize is still an alpha feature and may be removed in a future version.

Plugin installation

Install using curl (on OSX or Linux):

OS=$(uname | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m | sed 's/x86_64/amd64/; s/aarch64/arm64/')
mkdir -p $HOME/.config/kustomize/plugin/khelm.mgoltzsche.github.com/v2/chartrenderer
curl -fsSL https://github.com/mgoltzsche/khelm/releases/latest/download/khelm-${OS}-${ARCH} > $HOME/.config/kustomize/plugin/khelm.mgoltzsche.github.com/v2/chartrenderer/ChartRenderer
chmod +x $HOME/.config/kustomize/plugin/khelm.mgoltzsche.github.com/v2/chartrenderer/ChartRenderer

or using go:

go get github.com/mgoltzsche/khelm/v2/cmd/khelm
mkdir -p $HOME/.config/kustomize/plugin/khelm.mgoltzsche.github.com/v2/chartrenderer
mv $GOPATH/bin/khelm $HOME/.config/kustomize/plugin/khelm.mgoltzsche.github.com/v2/chartrenderer/ChartRenderer

Plugin usage example

A plugin descriptor specifies the helm repository, chart, version and values that should be used in a kubernetes-style resource can be referenced in the generators section of a kustomization.yaml and can look as follows:

apiVersion: khelm.mgoltzsche.github.com/v2
kind: ChartRenderer
metadata:
  name: cert-manager # fallback for `name`
  namespace: cert-manager # fallback for `namespace`
repository: https://charts.jetstack.io
chart: cert-manager
version: 0.9.x
values:
  webhook:
    enabled: false

For all available fields see the table below.

More complete examples can be found within the example directory. For instance cert-manager can be rendered like this:

kustomize build --enable-alpha-plugins github.com/mgoltzsche/khelm/example/cert-manager

When using kustomize 3 the option is called --enable_alpha_plugins.

CLI

khelm also supports a helm-like template CLI.

Binary installation

OS=$(uname | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m | sed 's/x86_64/amd64/; s/aarch64/arm64/')
curl -fsSL https://github.com/mgoltzsche/khelm/releases/latest/download/khelm-${OS}-${ARCH} > khelm
chmod +x khelm
sudo mv khelm /usr/local/bin/khelm

Binary usage example

khelm template cert-manager --version=0.9.x --repo=https://charts.jetstack.io

For all available options see the table below.

Docker usage example

docker run mgoltzsche/khelm:latest template cert-manager --version=0.9.x --repo=https://charts.jetstack.io

Go API

The khelm Go API github.com/mgoltzsche/khelm/v2/pkg/helm provides a simple templating interface on top of the Helm Go API. It exposes a Helm struct that provides a Render() function that returns the rendered resources as kyaml objects.

Configuration options

Field CLI Description
chart ARGUMENT Chart file (if repository not set) or name.
version --version Chart version. Latest version is used if not specified.
repository --repo URL to the repository the chart should be loaded from.
valueFiles -f Locations of values files.
values --set Set values object or in CLI key1=val1,key2=val2.
apiVersions --api-versions Kubernetes api versions used for Capabilities.APIVersions.
kubeVersion --kube-version Kubernetes version used for Capabilities.KubeVersion.
name --name Release name used to render the chart.
verify --verify If enabled verifies the signature of all charts using the keyring (see Helm 3 provenance and integrity).
keyring --keyring GnuPG keyring file (default ~/.gnupg/pubring.gpg).
replaceLockFile --replace-lock-file Remove requirements.lock and reload charts when it is out of sync.
include List of resource selectors that include matching resources from the output. If no selector specified all resources are included. Fails if a selector doesn't match any resource. Inclusions precede exclusions.
include[].apiVersion Includes resources by apiVersion.
include[].kind Includes resources by kind.
include[].namespace Includes resources by namespace.
include[].name Includes resources by name.
exclude List of resource selectors that exclude matching resources from the output. Fails if a selector doesn't match any resource.
exclude[].apiVersion Excludes resources by apiVersion.
exclude[].kind Excludes resources by kind.
exclude[].namespace Excludes resources by namespace.
exclude[].name Excludes resources by name.
excludeCRDs --skip-crds If true Custom Resource Definitions are excluded from the output.
excludeHooks --no-hooks If enabled excludes chart hooks from the output.
namespace --namespace Set the namespace used by Helm templates.
namespacedOnly --namespaced-only If enabled fail on known cluster-scoped resources and those of unknown kinds.
forceNamespace --force-namespace Set namespace on all namespaced resources (and those of unknown kinds).
outputPath --output Path to write the output to. If it ends with / a kustomization is generated. (Not supported by the kustomize plugin.)
outputPathMapping[].outputPath output path to which all resources should be written that match resourceSelectors. (Only supported by the kpt function.)
outputPathMapping[].selectors[].apiVersion Selects resources by apiVersion.
outputPathMapping[].selectors[].kind Selects resources by kind.
outputPathMapping[].selectors[].namespace Selects resources by namespace.
outputPathMapping[].selectors[].name Selects resources by name.
--output-replace If enabled replace the output directory or file (CLI-only).
--trust-any-repo If enabled repositories that are not registered within repositories.yaml can be used as well (env var KHELM_TRUST_ANY_REPO). Within the kpt function this behaviour can be disabled by mounting /helm/repository/repositories.yaml or disabling network access.
debug --debug Enables debug log and provides a stack trace on error.

Repository configuration

Repository credentials can be configured using Helm's repositories.yaml which can be passed through as Secret to generic build jobs. khelm downloads the corresponding repo index files when needed.

When running khelm as kpt function or within a container the repositories.yaml should be mounted to /helm/repository/repositories.yaml.

Unlike Helm khelm allows usage of any repository when repositories.yaml is not present or --trust-any-repo (env var KHELM_TRUST_ANY_REPO) is enabled.

Helm support

  • Helm 2 is supported by the v1 module version.
  • Helm 3 is supported by the v2 module version.

Build and test

Build and test the khelm binary (requires Go 1.13) as well as the container image:

make clean khelm test check image e2e-test

The binary is written to build/bin/khelm.

Install the binary on your host at /usr/local/bin/khelm:

sudo make install
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].