Skip to main content

Deploy using Helm Chart

Last updated on

This topic explains how to deploy a sample application (Guestbook) using a publicly available Helm chart with Harness Continuous Delivery (CD).

Harness CD offers two ways to deploy the Guestbook application:

  • CD Pipeline: You build a Harness pipeline that deploys the Helm chart to your target cluster.
  • GitOps workflow: You install a Harness GitOps Agent, connect it to your Git repo and target cluster, and let Harness (using Argo CD) sync the desired state from Git into your cluster.
note

Sign up today to get started with Harness CD.


What will you learn in this topic?


Before you begin

Ensure you have the following:


Deploy the application

note

Harness resources such as delegates, secrets, and connectors can be created at the Account, Organization, or Project scope. For simplicity, this tutorial uses Project-scoped resources throughout. If you use resources from a different scope, update the configuration accordingly when you create connectors, environments, services, and the deployment pipeline.

Go to Organizations and projects to understand the Harness resource hierarchy and scopes.

You can deploy the Guestbook application using either a Harness CD pipeline or a Harness GitOps workflow.

Run the following command 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)

Deploy with a CD pipeline

Harness CD pipelines allow you to orchestrate and automate your deployment workflows and push updated application images to your target Kubernetes cluster. Pipelines allow extensive control over how you want to progress artifacts through various development, test, staging, or production clusters, when running a variety of scans and tests to ensure the quality and stability standards you and your team have defined.

You can proceed with the tutorial using either the Harness user interface (UI) or the command-line interface (CLI).

Perform the following steps to deploy the Guestbook application using Harness CD Pipeline UI:

  1. Log in to Harness Manager.
  2. Select Projects, and then select Default Project.
  3. After selecting the project, configure the core resources Harness requires to run a deployment, including a delegate, a secret, two connectors, an environment, a service, and a deployment pipeline, as explained in the following sections.
warning

For the pipeline to run successfully, follow the remaining steps as they are, including the naming conventions.

Delegate

The Harness Delegate is a service that runs in your local network or VPC to establish connections between the Harness Manager and various providers such as artifacts registries, cloud platforms, and so on. The delegate is installed in the target infrastructure, for example, a Kubernetes cluster, and performs operations including deployment and integration. Go to Delegate Overview to understand the delegate.

Perform the following steps to set up a delegate:

  1. Under Project Settings, select Delegates.

  2. Click New Delegate.

  3. Select Kubernetes in the Select where you want to install your Delegate section.

  4. In the Install your Delegate section, for this tutorial, install the delegate using Helm Chart.

  5. Add the Harness Helm chart repo to your local helm registry using the following command.

    helm repo add harness-delegate https://app.harness.io/storage/harness-download/delegate-helm-chart/
  6. Update the repo using the following command:

    helm repo update harness-delegate
  7. Copy and run the install command from the Delegate installation wizard as shown in the following example:

    Here, the ACCOUNT_ID, MANAGER_ENDPOINT and DELEGATE_TOKEN are auto-populated values you will get from the wizard itself.

    helm upgrade -i helm-delegate --namespace harness-delegate-ng --create-namespace \
    harness-delegate/harness-delegate-ng \
    --set delegateName=helm-delegate \
    --set accountId=ACCOUNT_ID \
    --set managerEndpoint=MANAGER_ENDPOINT \
    --set delegateDockerImage=harness/delegate:23.03.78904 \
    --set replicas=1 --set upgrader.enabled=false \
    --set delegateToken=DELEGATE_TOKEN
  8. Select Verify to verify that the delegate is installed successfully and can connect to the Harness Manager.

note

You can also follow the Install Harness Delegate on Kubernetes or Docker steps to install the delegate using the Harness Terraform Provider or a Kubernetes manifest.

Secrets

Harness offers built-in secret management for encrypted storage of sensitive information. Secrets are decrypted when needed, and only the private network-connected Harness Delegate has access to the key management system. You can also integrate your own secret manager. Go to Harness Secret Manager Overview to understand secrets in Harness.

Perform the following steps to add a secret:

  1. Under Project Settings, select Secrets.
  2. Click New Secret, and then select Text.
  3. In the Add new Encrypted Text page,
    1. Select the Secret Manager. For example, Harness Built-in Secret Manager.
    2. Enter the Secret Name. For example, harness_gitpat.
    3. For the Secret Value, paste the GitHub personal access token you saved earlier.
    4. Add the Description (Optional) and Tags (Optional).
    5. Select Save.

Connectors

Connectors in Harness enable integration with third party tools, providing authentication and operations during pipeline runtime. For instance, a GitHub connector facilitates authentication and fetching files from a GitHub repository within pipeline stages. Go to Connectors to explore connector how-tos.

Set up the GitHub connector

Perform the following steps to set up a GitHub connector:

  1. In your Harness project, under Project Settings, select Connectors.
  2. Select Create via YAML Builder and copy the contents of github-connector.yml into the YAML editor.
  3. Replace GITHUB_USERNAME with your GitHub account username in the YAML (assuming you have already forked the harnesscd-example-apps repo as noted in Before you begin).
  4. In projectIdentifier, verify that the project identifier is correct. You can see the Id in the browser URL (after account). If it is incorrect, the Harness YAML editor suggests the correct Id.
  5. Select Save Changes and verify that the new connector named harness_gitconnector is successfully created.
  6. Select Connection Test under Connectivity Status to ensure the connection is successful.

Set up the Kubernetes connector

Perform the following steps to set up a Kubernetes connector:

  1. In your Harness project, under Project Settings, select Connectors.
  2. Select Create via YAML Builder and copy the contents of kubernetes-connector.yml into the YAML editor.
  3. Replace DELEGATE_NAME with the installed Delegate name. To obtain the Delegate name, navigate to Project Settings, and then Delegates.
  4. Select Save Changes and verify that the new connector named harness_k8sconnector is successfully created.
  5. Select Connection Test under Connectivity Status to verify the connection is successful.

Deployment strategies

Helm is primarily focused on managing the release and versioning of application packages. Helm supports rollback through its release management features. When you deploy an application using Helm, it creates a release that represents a specific version of the application with a unique release name.

Harness performs canary and blue-green deployments with Helm as follows:

  • Harness integrates with Helm by using Helm charts and releases. Helm charts define the application package and its dependencies, and Helm releases represent specific versions of the application.
  • Harness allows you to define the application configuration, including Helm charts, values files, and any custom configurations required for your application.
  • In Harness, you can specify the percentage of traffic to route to the new version in a canary deployment or define the conditions to switch traffic between the blue and green environments in a blue-green deployment.
  • Harness orchestrates the deployment workflow, including the deployment of Helm charts, by interacting with the Helm API. It manages the release lifecycle, tracks revisions, and controls the rollout process based on the defined canary or blue-green strategy.

Harness adds an additional layer of functionality on top of Helm, providing an automated approach to canary and blue-green deployments. By using Helm's package management capabilities and integrating with its release management features, Harness extends Helm to support canary and blue-green deployment strategies.

Pick a deployment strategy from the following:

A canary deployment updates nodes in a single environment gradually, allowing you to use gates between increments. Canary deployments allow incremental updates and ensure a controlled rollout process. Go to When to use Canary deployments to understand when to use them.

Environment

Environments define the deployment location, categorized as Production or Pre-Production. Each environment includes infrastructure definitions for VMs, Kubernetes clusters, or other target infrastructures. Go to Environments overview to understand environments.

Perform the following steps to set up an environment:

  1. In Default Project, select Environments.
  2. Select New Environment and toggle to the YAML view.
  3. Copy the contents of k8s-environment.yml, paste it into the YAML editor, and then select Save.
  4. In the Infrastructure Definitions tab, select Infrastructure Definition, and then select Edit YAML.
  5. Copy the contents of k8s-infrastructure-definition.yml and paste it into the YAML editor.
  6. Select Save and verify that the environment and infrastructure definition are created successfully.

Service

In Harness, services represent what you deploy to an environment. You use services to configure variables, manifests, and artifacts. The Services dashboard provides service statistics such as deployment frequency and failure rate. Go to Services overview to understand services.

Perform the following steps to set up a service:

  1. In Default Project, select Services.
  2. Select New Service, enter the name harnessguestbookdep, and then select Save.
  3. On the Configuration tab, toggle to the YAML view, and then select Edit YAML.
  4. Copy the contents of k8s-service.yml and paste it into the YAML editor.
  5. Select Save and verify that the service harness_guestbook is successfully created.

Pipeline

A pipeline is a comprehensive process encompassing integration, delivery, operations, testing, deployment, and monitoring. It can use CI for code building and testing, followed by CD for artifact deployment in production. A CD Pipeline is a series of stages where each stage deploys a service to an environment. Go to CD pipeline basics to understand CD pipelines.

Perform the following steps to set up a pipeline with canary deployment:

  1. In Default Project, select Pipelines.
  2. Select New Pipeline.
  3. Enter the name guestbook_canary_pipeline.
  4. Select Inline to store the pipeline in Harness.
  5. Select Start and, in the Pipeline Studio, toggle to YAML to use the YAML editor.
  6. Select Edit YAML to enable edit mode, copy the contents of k8s-canary-pipeline.yml, and paste it into the YAML editor.
  7. Select Save.

You can switch to the Visual pipeline editor and confirm the pipeline stage and execution steps as shown below.

Canary

Run the pipeline

Perform the following steps to execute the pipeline:

  1. In the Pipeline Studio, select Run, and then select Run Pipeline to initiate the deployment.

  2. Observe the execution logs as Harness deploys the workload and checks for steady state.

  3. After a successful execution, you can check the deployment on your Kubernetes cluster using the following command:

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

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

Deploy your own application

Follow these steps to deploy your own application using a Harness CD pipeline instead of the sample Guestbook application.

  • Use the same delegate that you deployed as part of this tutorial. Alternatively, deploy a new delegate, but remember to use a newly created delegate identifier when creating connectors.

  • If you intend to use a private Git repository that hosts your Helm chart, create a Harness secret containing the Git personal access token (PAT). Subsequently, create a new Git connector using this secret.

  • Create a Kubernetes connector if you plan to deploy your applications in a new Kubernetes environment. Ensure to update the infrastructure definition to reference this newly created Kubernetes connector.

  • Once you complete all the aforementioned steps, create a new Harness service that leverages the Helm chart for deploying applications.

  • Establish a new deployment pipeline and select the newly created infrastructure definition and service. Choose a deployment strategy that aligns with your microservice application's deployment needs.


Next steps

You have deployed the Guestbook application with Harness CD using a Helm chart.

Continue your learning journey with the following: