Feedback

Chat Icon

GitOps the Hard Way, with Argo CD

Build Real GitOps Pipelines From Empty Clusters to Automated Deploys

Argo CD With Helm: Charts, Values, and Versioned Releases
77%

Creating a Helm Chart for Our Application

In this section, we will create a Helm chart for our app. I assume you have a basic understanding of Helm. If you are not familiar with Helm, you can check the official documentation, or you can find my Helm in Practice course on FAUN.dev().

Here are some of the basic concepts:

  • Chart: Helm's packaging format. It is a set of files describing Kubernetes resources that can be shared and installed.
  • Template: To deploy resources, Helm uses dynamically rendered Kubernetes manifests generated from customizable files. These files are called "templates" and are generated based mainly on values defined in the values.yaml file.
  • Values: A file that contains the default values used to generate the final Kubernetes manifests from templates. This file can be used by the user to customize Kubernetes resources like Deployment, Service, ConfigMap, and so on.
  • Release: An instance of a chart installed in a cluster by helm install, tracked by Helm as a named, versioned object. Argo CD renders charts with helm template and does not create releases: it tracks application state itself.
  • Repository: A collection of charts that can be shared and installed by others.

(i) Helm uses values from values.yaml to render the templates, and those templates produce the Kubernetes resources Argo CD applies.

Standalone Helm vs Argo CD with Helm

Standalone Helm vs Argo CD with Helm


Let's start by creating a Helm chart for our todo app. First, install Helm on your gitops server by following the official installation guide. The fastest installation method is to use the helm installer script:

# The URL of the Helm installation script
HELM_URL="https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-4"

# Download the installation script
curl -fsSL -o get_helm.sh $HELM_URL

# Make the script executable
chmod 700 get_helm.sh

# Run the installation script
./get_helm.sh

# Remove the installation script
rm get_helm.sh

This is how to start a fresh Helm chart for our todo app:

mkdir -p $HOME/todo/app/manifests/helm && \
  cd $HOME/todo/app/manifests/helm && \
  helm create todo

This is the file tree of our Helm chart:

$HOME/todo/app/manifests/helm/todo
├── Chart.yaml
├── charts
├── templates
│   ├── NOTES.txt
│   ├── _helpers.tpl
│   ├── deployment.yaml
│   ├── hpa.yaml
│   ├── httproute.yaml
│   ├── ingress.yaml
│   ├── service.yaml
│   ├── serviceaccount.yaml
│   └── tests
│       └── test-connection.yaml
└── values.yaml

Next, let's update the values.yaml file to adapt the default installation to our needs.

We already exported the image name to the $IMAGE_NAME variable and it looks like this:

echo $IMAGE_NAME
# Example output:
# registry.gitlab.com/learning9042634/todo:v0

We need to separate the repository and the tag to use them in values.yaml, since the image field there has two subfields: repository and tag. We can use the cut command to separate the repository and the tag from $IMAGE_NAME:

cat <> $HOME/.bashrc && source $HOME/.bashrc
export IMAGE_REGISTRY=$(echo $IMAGE_NAME | cut -d: -f1)
export IMAGE_TAG=$(echo $IMAGE_NAME | cut -d: -f2)
EOF

Now, update values.yaml with the following content:

cat < $HOME/todo/app/manifests/helm/todo/values.yaml
# Number of pods to run
replicaCount: 1

image:
  # Container image repository
  repository: $IMAGE_REGISTRY
  # Image tag or version
  tag: $IMAGE_TAG
  # Pull policy: Always, IfNotPresent, or Never
  pullPolicy: IfNotPresent

service:
  # Service type: ClusterIP, NodePort, or LoadBalancer
  type: NodePort

GitOps the Hard Way, with Argo CD

Build Real GitOps Pipelines From Empty Clusters to Automated Deploys

Enroll now to unlock all content and receive all future updates for free.