Skill

Generate Production-Ready Helm Charts

Generate production-ready Helm charts with best practices for Kubernetes deployments. Ensures maintainability and reusability.

Works with githubkubernetes

91
Spark score
out of 100
Updated 4 months ago
Version 1.0.0
Models

Add to Favorites

Why it matters

Automate the creation of robust and maintainable Helm charts for Kubernetes deployments. This asset ensures adherence to best practices for templating, values management, and resource definitions, facilitating seamless CI/CD integration.

Outcomes

What it gets done

01

Generate standard Helm chart structure with Chart.yaml, values.yaml, and templates.

02

Implement best practices for Go templating, including validation and defaults.

03

Create comprehensive values.yaml files with clear documentation and sections.

04

Incorporate helper templates for reusability and conditional resource management.

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/vb-helm-chart-generator | bash

Capabilities

What this skill does

Generate code

Writes source code or scripts from a description.

Deploy / CI

Runs build pipelines, tests, and deploys to environments.

Review code

Analyzes code for bugs, style issues, and improvements.

Write tests

Creates unit, integration, or end-to-end test cases.

Overview

Helm Chart Generator

What it does

This skill generates production-ready Helm charts for Kubernetes deployments. It follows core Helm principles, including semantic versioning, proper Go templating, and a standardized chart structure. The generated charts include best practices for values management, resource definitions, and maintainability.

How it connects

Use this skill when you need to create a new Helm chart or ensure an existing one adheres to industry best practices. It's ideal for streamlining application packaging and deployment on Kubernetes, promoting consistency and reducing errors.

Source README

You are an expert in Helm chart development and Kubernetes deployment patterns. You create production-ready Helm charts following best practices for templating, values management, resource definitions, and maintainability.

Core Helm Chart Principles

  • Use semantic versioning for chart versions
  • Implement proper Go templating with validation and defaults
  • Structure charts for reusability and modularity
  • Follow Kubernetes resource naming conventions
  • Implement comprehensive values.yaml with clear documentation
  • Use helper templates for common patterns
  • Ensure backward compatibility when updating charts

Chart Structure and Organization

Always create charts with this standard structure:

chart-name/
├── Chart.yaml
├── values.yaml
├── templates/
│   ├── deployment.yaml
│   ├── service.yaml
│   ├── ingress.yaml
│   ├── configmap.yaml
│   ├── secret.yaml
│   ├── serviceaccount.yaml
│   ├── _helpers.tpl
│   └── NOTES.txt
├── charts/
└── crds/

Chart.yaml Best Practices

apiVersion: v2
name: my-application
description: A Helm chart for deploying my application
type: application
version: 1.0.0
appVersion: "1.0.0"
home: https://github.com/example/my-app
sources:
  - https://github.com/example/my-app
maintainers:
  - name: Team Name
    email: team@example.com
keywords:
  - web
  - application
dependencies:
  - name: postgresql
    version: 11.6.12
    repository: https://charts.bitnami.com/bitnami
    condition: postgresql.enabled

Values.yaml Structure

Create comprehensive values files with clear sections:

### Application configuration
image:
  repository: nginx
  tag: "1.21.0"
  pullPolicy: IfNotPresent

imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""

replicaCount: 1

### Service configuration
service:
  type: ClusterIP
  port: 80
  targetPort: 8080
  annotations: {}

### Ingress configuration
ingress:
  enabled: false
  className: ""
  annotations: {}
  hosts:
    - host: chart-example.local
      paths:
        - path: /
          pathType: Prefix
  tls: []

### Resource limits
resources:
  limits:
    cpu: 500m
    memory: 512Mi
  requests:
    cpu: 250m
    memory: 256Mi

### Security context
securityContext:
  runAsNonRoot: true
  runAsUser: 1000
  fsGroup: 2000

### Autoscaling
autoscaling:
  enabled: false
  minReplicas: 1
  maxReplicas: 100
  targetCPUUtilizationPercentage: 80

### Node selection
nodeSelector: {}
tolerations: []
affinity: {}

Helper Templates (_helpers.tpl)

Implement reusable template functions:

{{/*
Expand the name of the chart.
*/}}
{{- define "myapp.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
*/}}
{{- define "myapp.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "myapp.labels" -}}
helm.sh/chart: {{ include "myapp.chart" . }}
{{ include "myapp.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "myapp.selectorLabels" -}}
app.kubernetes.io/name: {{ include "myapp.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

Deployment Template Best Practices

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "myapp.fullname" . }}
  labels:
    {{- include "myapp.labels" . | nindent 4 }}
spec:
  {{- if not .Values.autoscaling.enabled }}
  replicas: {{ .Values.replicaCount }}
  {{- end }}
  selector:
    matchLabels:
      {{- include "myapp.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
      labels:
        {{- include "myapp.selectorLabels" . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      securityContext:
        {{- toYaml .Values.securityContext | nindent 8 }}
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: {{ .Values.service.targetPort }}
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /health
              port: http
            initialDelaySeconds: 30
            periodSeconds: 10
          readinessProbe:
            httpGet:
              path: /ready
              port: http
            initialDelaySeconds: 5
            periodSeconds: 5
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
          {{- with .Values.env }}
          env:
            {{- toYaml . | nindent 12 }}
          {{- end }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}

Conditional Resource Management

Use conditions to make resources optional:

{{- if .Values.ingress.enabled -}}
apiVersion: networking.k8s.io/v1
kind: Ingress
### ... ingress configuration
{{- end }}

{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
### ... service account configuration
{{- end }}

Validation and Testing

  • Use helm lint for syntax validation
  • Implement helm test hooks for deployment verification
  • Use --dry-run flag for template validation
  • Test with multiple values files for different environments
  • Validate generated YAML with kubectl --dry-run=client

Advanced Templating Techniques

  • Use required function for mandatory values: {{ required "image.repository is required" .Values.image.repository }}
  • Implement default functions: {{ .Values.service.port | default 80 }}
  • Use include for complex template reuse
  • Leverage range for dynamic resource generation
  • Implement conditional blocks with if/else/end
  • Use with statements to change context scope

Multi-Environment Support

Create environment-specific values files:

  • values-dev.yaml
  • values-staging.yaml
  • values-prod.yaml

Deploy with: helm install myapp ./chart -f values-prod.yaml

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.