Skip to main content

Deploy using Helm Chart

This tutorial is designed to help you get started with Harness Continuous Delivery (CD). We will guide you through creating a CD pipeline/GitOps for deploying a Guestbook application. This Guestbook application will use Helm Chart for deployment.

info

Kubernetes is required to complete these steps. Run the following to check your system resources and (optionally) install a local cluster.

bash <(curl -fsSL https://raw.githubusercontent.com/harness-community/scripts/main/delegate-preflight-checks/cluster-preflight-checks.sh)
info

Whether you're new to GitOps or already have an Argo CD instance, this guide will assist you in getting started with Harness GitOps, both with and without Argo CD.

Harness also offers a Hosted GitOps solution. A tutorial for it will be available soon.

Before you begin

Make sure that you have met the following requirements:

Deploy your applications using Harness GitOps

  1. Log in to the Harness App.

  2. Select Projects in the top left corner of the UI, and then select Default Project.

  3. In Deployments, select GitOps.

Install a Harness GitOps Agent

What is a GitOps Agent?

A Harness GitOps Agent is a worker process that runs in your environment, makes secure, outbound connections to Harness, and performs all the GitOps tasks you request in Harness.

  1. Select Settings on the top right corner of the UI.
  2. Select GitOps Agents, and then select New GitOps Agent.
  3. In Do you have any existing Argo CD instances?, select Yes if you already have an Argo CD instance, else select No to install the Harness GitOps Agent.
  1. In Do you have any existing Argo CD instances?, select No, and then select Start.
  2. In Name, enter the name for the new Agent.
  3. In Namespace, enter the namespace where you want to install the Harness GitOps Agent. Typically, this is the target namespace for your deployment. For this tutorial, let's use the default namespace to install the Agent and deploy applications.
  4. Select Continue. The Review YAML settings appear. This is the manifest YAML for the Harness GitOps Agent. You can download this YAML file and run it in your Harness GitOps Agent cluster.
    kubectl apply -f gitops-agent.yml -n default
  5. Select Continue and verify that the Agent is successfully installed and can connect to Harness Manager.
  1. Download and Configure Harness CLI.
curl -LO https://github.com/harness/harness-cli/releases/download/v0.0.25-Preview/harness-v0.0.25-Preview-darwin-amd64.tar.gz
tar -xvf harness-v0.0.25-Preview-darwin-amd64.tar.gz
export PATH="$(pwd):$PATH"
echo 'export PATH="'$(pwd)':$PATH"' >> ~/.bash_profile
source ~/.bash_profile
harness --version
  1. Clone the Forked harnesscd-example-apps repo and change directory.

    git clone https://github.com/GITHUB_ACCOUNTNAME/harnesscd-example-apps.git
    cd harnesscd-example-apps
    note

    Replace GITHUB_ACCOUNTNAME with your GitHub Account name.

  2. Log in to Harness from the CLI.

    harness login --api-key  --account-id HARNESS_API_TOKEN
    note

    Replace HARNESS_API_TOKEN with Harness API Token that you obtained during the prerequisite section of this tutorial.

warning

For the pipeline to run successfully, please follow all of the following steps as they are, including the naming conventions.

Add a Harness GitOps repository

What is a GitOps Repository?

A Harness GitOps Repository is a repository containing the declarative description of a desired state. The declarative description can be in Kubernetes manifests, Helm Chart, Kustomize manifests, etc.

Use the following command to add a Harness GitOps repository.

harness gitops-repository --file helm-guestbook/harness-gitops/repository.yml apply --agent-identifier $AGENT_NAME

Add a Harness GitOps cluster

What is a GitOps Cluster?

A Harness GitOps Cluster is the target deployment cluster that is compared to the desire state. Clusters are synced with the source manifests you add as GitOps Repositories.

Use the following command to add a Harness GitOps cluster.

harness gitops-cluster --file helm-guestbook/harness-gitops/cluster.yml apply --agent-identifier $AGENT_NAME

Add a Harness GitOps application

What is a GitOps Application?

GitOps Applications are how you manage GitOps operations for a given desired state and its live instantiation.

A GitOps Application collects the Repository (what you want to deploy), Cluster (where you want to deploy), and Agent (how you want to deploy). You select these entities when you set up your Application.

Use the following command to create a Gitops application

harness gitops-application --file helm-guestbook/harness-gitops/application.yml apply --agent-identifier $AGENT_NAME

Sync the application

Finally, it's time to Synchronize the application state.

  1. Select Sync in the top right corner of the UI.
  2. Check the application details, and then select Synchronize to initiate the deployment.
    • After a successful execution, you can check the deployment on your Kubernetes cluster using the following command:

      kubectl get pods -n default
    • To access the Guestbook application deployed via the Harness pipeline, port forward the service and access it at http://localhost:8080:

      kubectl port-forward svc/<service-name> 8080:80

      On successful application sync, you'll see the status tree under Resource View as shown below:

GitOps

Congratulations!🎉

You've just learned how to use Harness CD to deploy application using a Helm Chart template.

Keep learning about Harness CD. Add Triggers to your pipeline that'll respond to Git events. For more information, go to Triggering pipelines.