Lab 10.3 - Creating a Custom Chart
Lab Objectives
By the end of this lab, you will be able to:
- Create a Helm Chart with helm create.
- Understand the structure of a Chart.
- Modify templates.
- Use values in templates.
- Package and install your Chart.
Estimated Duration
60-75 minutes
Prerequisites
- Helm installed and configured.
- Local Kubernetes cluster running.
- Knowledge of Helm Charts (Chapter 10.3).
Part 1: Creating a Chart
Step 1.1: Create a New Chart
Create a new Chart:
helm create my-app-chart
Examine the structure:
tree my-app-chart
# or
ls -la my-app-chart/
Part 2: Chart Structure
Step 2.1: Examine the Files
Examine the main files:
# Chart.yaml
cat my-app-chart/Chart.yaml
# values.yaml
cat my-app-chart/values.yaml
# Templates
ls my-app-chart/templates/
Part 3: Customizing the Chart
Step 3.1: Modify Chart.yaml
Edit my-app-chart/Chart.yaml:
apiVersion: v2
name: my-app-chart
description: A custom Helm Chart for my application
type: application
version: 0.1.0
appVersion: "1.0"
Step 3.2: Modify values.yaml
Edit my-app-chart/values.yaml:
replicaCount: 2
image:
repository: nginx
pullPolicy: IfNotPresent
tag: "1.20"
service:
type: ClusterIP
port: 80
ingress:
enabled: false
Part 4: Modifying Templates
Step 4.1: Examine a Template
Look at the Deployment template:
cat my-app-chart/templates/deployment.yaml
Step 4.2: Customize the Template
Modify the template to add environment variables:
# In deployment.yaml, add in the container:
env:
- name: APP_NAME
value: {{ .Values.nameOverride | default .Chart.Name }}
Part 5: Testing and Installation
Step 5.1: Validate the Chart
Validate the syntax:
helm lint my-app-chart
Step 5.2: Dry-Run
Test without installing:
helm install my-app my-app-chart --dry-run --debug
Step 5.3: Install the Chart
Install your Chart:
helm install my-app my-app-chart
Verify:
helm list
kubectl get all -l app.kubernetes.io/instance=my-app
Part 6: Packaging
Step 6.1: Package the Chart
Create a package:
helm package my-app-chart
This creates a .tgz file.
Step 6.2: Install from the Package
Install from the package:
helm install my-app-from-package my-app-chart-0.1.0.tgz
Part 7: Cleanup
helm uninstall my-app my-app-from-package
rm -rf my-app-chart my-app-chart-0.1.0.tgz
Lab Summary
In this lab, you created your first custom Helm Chart. You learned the structure of a Chart, how to modify templates, and how to package your Chart.
Next Steps
The last lab of this module will show you how to use Helmfile for multi-environment management.
Lab 10.4: Helmfile and Multi-environments
Lab created on: December 2024