Example: Integrating CDA with HELM

This scenario describes how to integrate CDA with HELM, from code development to the Kubernetes cluster deployment.

This page includes the following:

Overview

  1. An Application Developer pushes a commit to a remote GIT repository.
  2. A webhook in Gogs (self hosting GIT repository) triggers a job in Jenkins.
  3. Jenkins builds a Docker image and sends it to Docker Hub.
  4. A Helm Chart is packaged and uploaded to ChartMuseum (Helm repository).
  5. The helm2rm CLI tool is executed to generate a CDA Application from the Helm Chart.
  6. The Operator selects a target cluster and triggers a deployment.
  7. The helm2rm CLI tool uses the Helm actions to generate a deployment workflow and deploy a Helm Chart to a target cluster. The status of the deployed containers are displayed in CDA.

System Requirements

Gogs

Gogs is a self hosting GIT service. You can download it from the official Gogs site. Gogs can also be deployed using Helm :

helm install --name mygogs --set serviceType=NodePort incubator/gogs

Jenkins

  1. Copy the Helm CLI and the helm2rm CLI tool to the Jenkins agent. Make sure these tools are added to the PATH environment variable.
  2. Install the Gogs plugin for Jenkins.

ChartMuseum

ChartMuseum is a Helm repository. You can download it from the ChartMuseum repository on Github. ChartMuseum can also be deployed using Helm:

helm install --name my-chartmuseum --set service.type=NodePort,env.open.DISABLE_API=false stable/chartmuseum

DockerHub

A DockerHub account is required.

CDA

PCK.AUTOMIC_HELM has to be installed in order to provide the necessary Custom Types and Actions.

Integration Setup

For this scenario, a Microblog application will be used. A Microblog application is a web application written in Python that works with a MYSQL database. The Helm chart for this application is already defined in the helm_chart folder. The helm chart contains:

To Set Up the Integration

  1. Log into Gogs and create a new repository.
  2. Push the Application code to the new repository.

    Note: You can clone the code of the Microblog application from https://github.com/cuongbm/microblog.

  3. To integrate Gogs and Jenkins, log into Jenkins and create a new Freestyle project.
  4. In Source Code Management, select Git and enter the URL of the repository created in Gogs.
  5. Add the Gogs account credentials.
  6. Go to Gogs, open the repository settings and add a new Gogs webhook.
  7. In the Payload URL field, enter http://<Jenkins host>/gogs-webhook/?job=microblog. Click Test delivery to ensure that everything works as expected.

Jenkins Job configuration

  1. Configure the following steps in Jenkins:

    • Build step: Create docker image and push to Docker Hub registry

      • Command to build an image from a Dockerfile and add a tag in the "name:tag" format:

        docker build -t repositoryname/microblog:1.0.0-$BUILD_NUMBER

      • Command to push an image to the Docker Hub registry:

        docker push repositoryname/microblog:1.0.0-$BUILD_NUMBER

    • Build step: Packaging Helm chart

      This step uses the Helm CLI to create a package and replace the application and package versions.

      helm init --client-only

      helm dependency build helm_chart/microblog/

      helm package --app-version 1.0.0-$BUILD_NUMBER --version=1.0.0+$BUILD_NUMBER helm_chart/microblog/

      curl --data-binary "@microblog-1.0.0+$BUILD_NUMBER.tgz" http://192.168.99.100:30100/api/charts

      Note: Replace the IP address with your ChartMuseum URL

    • Build step: Synchronize theHelm chart with the CDA application

      rm -r helm_chart/unpack

      mkdir helm_chart/unpack

      tar -zxvf microblog-1.0.0+$BUILD_NUMBER.tgz -C helm_chart/unpack

      helm2rm sync --set connection.url=http://cdaserver-host/rm,connection.username=10/API/API,connection.password=123,parentComponent.chartLocation=http://123.456.78.100:30100/charts/microblog-1.0.0+$BUILD_NUMBER.tgz $WORKSPACE/helm_chart/unpack/microblog/

      Note: The chartLocation must be set to the chart URL in ChartMuseum . This will be set in the Component Dynamic Property. Then, it will be passed to the Helm CLI on the target Kubernetes cluster. At that step, the chart will be downloaded from Chart Museum.

  2. Save the build and click Build Now manually to see if everything works correctly.

Deploy a Helm Chart from CDA

From now on, every push to the Gogs server will trigger the build in Jenkins and a CDA application will be created/updated automatically using the Helm2Rm CLI. With every new build, a new Package will be created.

The following entities will be created in CDA:

Important! Before triggering the deployment workflow, ensure that Helm CLI is installed on the Deployment Target Agent and added to the PATH environment variable. Helm CLI with take care of the deployment to the Kubernetes cluster.

With CDA, the access to the Kubernetes cluster is well controlled using our existing security model. Only users with proper permissions can execute the deployment.

The installation records in CDA reflect the container deployments status:

The information is shown in the Installations view, the Deployment Pipeline widget and the Deployment Timeline widget.