Feedback

Chat Icon

Cloud Native CI/CD with GitLab

From Commit to Production Ready

Multi-Stage Continuous Deployment with GitLab, Helm and Kubernetes
94%

Using Helm: The Kubernetes Package Manager

Using Kubernetes manifests directly can be cumbersome, especially when you have multiple resources or multiple environments to manage. Helm is a package manager for Kubernetes that helps you define, install, and manage Kubernetes applications. Helm uses charts, which are packages of pre-configured Kubernetes resources. Charts can be shared and reused and are versioned like any other package manager.

In this section, we will use Helm to package our application and deploy it to our cluster. Let's start by installing Helm on our "dev" machine (this is already done in one of the previous sections) but let's verify the installation:

helm version

If you don't have Helm installed, you can follow the following steps to install it:

# Download the Helm binary
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
# Install Helm
chmod 700 get_helm.sh
./get_helm.sh
rm get_helm.sh

Let's create a Helm chart for our application. We will use the following command to create the chart:

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
│   ├── 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:

registry.gitlab.com/learning9042634/todo:v0

We need to separate the repository and the tag to use them in the values.yaml file.

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 the values.yaml file with the following content:

cat < $HOME/todo/app/manifests/helm/todo/values.yaml
# Define the number of replicas for the deployment.
# This specifies how many instances (pods)
# of the application will run.
replicaCount: 1

# Define the Docker image details for the application.
image:
  # The container image repository to pull from,
  # configurable via environment variables.
  repository: $IMAGE_REGISTRY
  # The image tag/version,
  # also configurable via environment variables.
  tag: $IMAGE_TAG
  # The pull policy for the image
  # e.g., Always, IfNotPresent, or Never
  pullPolicy: IfNotPresent

# Configuration for the service that exposes the application.
service:
  # The type of service to create
  # e.g., ClusterIP, NodePort, or LoadBalancer
  type: NodePort
  # The port number on which the service will be exposed.
  port: 5000

# Resource allocation for the pods to define limits and requests.
resources:
  # The maximum amount of resources (CPU/memory) a pod can use.
  limits:
    # Maximum CPU usage of 100 millicores (0.1 CPU).
    cpu:

Cloud Native CI/CD with GitLab

From Commit to Production Ready

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