If you’ve ever managed Helm charts, you know the struggle. Writing and maintaining Helm charts is no easy feat, especially when dealing with complex umbrella charts that include a web of subcharts. The challenge multiplies when trying to maintain consistency, handle dynamic values, and simplify your deployment process. The time it takes can be overwhelming and frustrating.
How We Solved This at XMCyber
At XMCyber, we felt these pain points deeply. We needed a better way to manage Helm charts that didn’t consume hours of development time and reduce efficiency. To solve this, we developed our own Global Templates Library Chart. This reusable library has become a crucial part of our workflow, making it easier for our developers to write and maintain charts without wrestling with complex Helm syntax.
Introducing the XM Helm Global Templates Library
Our library provides a set of reusable Helm templates that simplify and standardize Helm chart development. By centralizing commonly used templates, we maintain consistency across charts and allow developers to focus on their applications instead of repetitive code.
Getting Started with the Library
Here’s how to get started with the XM Helm Global Templates Library:
Step 1: Installation
Add the repository:
helm repo add xm-global-templates https://xmcyber.github.io/helm-global-templates/
Then, add the dependency to your Chart.yaml
:
dependencies:
- name: xm-global-templates
version: 1.1.0 # Use the latest version
repository: https://xmcyber.github.io/helm-global-templates/
import-values:
- default
Step 2: Include Global Templates
In your chart, create a single template file and include the templates you want to render. Here’s an example of how to include a Deployment, Service, and ConfigMap using the global templates:
{{ include "global-templates.deployment" (dict "deployments" .Values.deployments "Chart" .Chart "Release" .Release "Capabilities" .Capabilities "Files" .Files "Template" .Template "Values" .Values) }}
{{ include "global-templates.service" (dict "services" .Values.services "Chart" .Chart "Release" .Release "Capabilities" .Capabilities "Files" .Files "Template" .Template "Values" .Values) }}
{{ include "global-templates.configmap" (dict "configmaps" .Values.configmaps "Chart" .Chart "Release" .Release "Capabilities" .Capabilities "Files" .Files "Template" .Template "Values" .Values) }}
Example values.yaml
for Basic Usage
Define your resources in the values.yaml
file to be rendered by the global templates:
api_port: &api_port 3000
api_namespace: &api_namespace api-namespace
api_configmap_name: &api_configmap_name api-cm
deployments:
- name: api
namespace: *api_namespace
replicas: 1
containers:
- name: api-container
image:
registry: docker.io
repository: busybox
tag: 1.0.0
ports:
- containerPort: *api_port
envFrom:
- configMapRef:
name: *api_configmap_name
services:
- name: api
namespace: *api_namespace
ports:
- port: *api_port
targetPort: *api_port
protocol: TCP
configmaps:
- name: *api_configmap_name
namespace: *api_namespace
data:
key: value
Making Life Easier for Developers
The goal of the XM Helm Global Templates Library is to remove the unnecessary complexities of Helm chart development. By providing reusable templates, developers can focus on building and deploying their applications rather than wrestling with Helm syntax. This shift has helped us write and maintain Helm charts 150% faster, and we believe it can help you too.
Advanced Tips and Tricks: Dynamic Value Generation and Manipulation
In our specific charts, we needed to generate values dynamically according to the input from the chart. We created a way to inject and manipulate values directly within the values.yaml file, offering a flexible approach that reduces complexity and maintenance overhead. This adds a layer of flexibility that was previously difficult to achieve without complex tpl functions.
Example of dynamic-values
# Define dynamic values in the global scope
global:
key: injected
deployments:
- name: app
namespace: default
containers:
- name: app
image:
registry: docker.io
repository: busybox
tag: latest
ports:
- containerPort: 8080
env:
- name: INJECTED_WORD
value: "This is going to be {{ global.key }} here" # Inject the key here
In this example, the INJECTED_WORD
variable is dynamically set to This is going to be injected here.
Your Feedback Matters
We’re excited to announce that we have just released this project as open-source, and we’d love to hear from you! Check it out here: https://github.com/XMCyber/helm-global-templates. Your feedback and experiences will help us improve and expand the tool to make Helm chart management even simpler.
Thanks for reading, and we hope this makes your Helm chart journey a little smoother. Let us know what you think!
We’d love to hear your stories, pain points, and wins. Drop your comments or questions below!
Top comments (0)