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.

Sign up today to unleash the potential of intelligent Harness CD.

Before you begin

Make sure that you have met the following requirements:

Deploy your applications using a Helm template

  1. Log in to the Harness App.

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

caution

Follow the below mentioned steps as they are, including the naming conventions, for the pipeline to run successfully.

Set up a delegate

What is the Harness 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, etc. The delegate is installed in the target infrastructure, for example, a Kubernetes cluster, and performs operations including deployment and integration. Learn more about the delegate in the Delegate Overview.

  1. In PROJECT SETUP, select Delegates, and then select Tokens on the top right corner of the UI.

    • Select New Token.
    • In the New Token dialog, in Name, enter delegate_token.
    • Select Apply.
    • Copy the token value by selecting the copy icon. Make sure to save the token now. You won't be able to see it again.
    • Close the New Token dialog.
  2. Select Delegates on the top right corner of the UI.

    • Select New Delegate. For this tutorial, let's explore how to install the delegate using Helm.

    • In Select where you want to install your Delegate, select Kubernetes.

    • In Install your Delegate, select Helm.

    • Add the Harness Helm Chart repository to your local helm registry using the following commands:

      helm repo add harness-delegate https://app.harness.io/storage/harness-download/delegate-helm-chart/
      helm repo update harness-delegate
    • Replace DELEGATE_TOKEN with the token copied in the previous step, and proceed to install the delegate. ACCOUNT_ID and MANAGER_ENDPOINT are auto-populated values that you can obtain from the Delegate Installation wizard.

      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
    • Verify that the delegate is installed successfully and can connect to the Harness Manager.

You can also Install Harness Delegate on Kubernetes or Docker Terraform Helm Provider or Kubernetes Manifest.

Create a secret

What are Harness 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. To learn more about secrets in Harness, go to Harness Secret Manager Overview.

  1. In PROJECT SETUP, select Secrets.
  2. Select New Secret, and then select Text.
  3. In the Add new Encrypted Text dialog:
    • In Secret Name, enter harness_gitpat.
    • In Secret Value, enter your GitHub PAT.
  4. Select Save.

Create a connector

What are connectors?

Connectors in Harness enable integration with 3rd 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. Explore connector how-tos here.

  1. Create a GitHub connector.
    1. In PROJECT SETUP, select Connectors, and then select Create via YAML Builder.
    2. Copy and paste the contents of 1-github-connector.yml.
    3. Replace GITHUB_USERNAME with your GitHub account username in the YAML wherever required. We assume that you have already forked the harnessed-example-apps repository as mentioned in the Before you begin section.
    4. Select Save Changes, and verify that the new connector named harness_gitconnector is successfully created.
    5. Select Connection Test under Connectivity Status to ensure that the connection is successful.
  2. Create a Kubernetes connector.
    1. In PROJECT SETUP, select Connectors, and then select Create via YAML Builder.
    2. Copy and paste the contents of 2-kubernetes-connector.yml.
    3. Replace DELEGATE_NAME with the installed delegate name. To obtain the delegate name, navigate to Default Project > PROJECT SETUP > 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 ensure that the connection is successful.

Create an environment

What are Harness environments?

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

  1. In Default Project, select Environments.
  2. Select New Environment and toggle to the YAML view (next to VISUAL).
  3. Copy the contents of 3-environment.yml and paste it in 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 4-infrastructure-definition.yml and paste it in the YAML editor.
  6. Select Save and verify that the environment and infrastructure definition are created successfully.

Create a service

What are Harness services?

In Harness, services represent what you deploy to environments. You use services to configure variables, manifests, and artifacts. The Services dashboard provides service statistics like deployment frequency and failure rate. To learn more about services, go to Services overview.

  1. In Default Project, select Services.
  2. Select New Service, enter the name, harnessguestbook, and then select Save.
  3. Toggle to the YAML view (next to VISUAL) under the Configuration tab, and then select Edit YAML.
  4. Copy the contents of 5-service.yml and paste it in the YAML editor.
  5. Select Save and verify that the service, harness_guestbook is successfully created.

Create a pipeline

What are Harness pipelines?

A pipeline is a comprehensive process encompassing integration, delivery, operations, testing, deployment, and monitoring. It can utilize 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. To learn more about CD pipeline basics, go to CD pipeline basics.

  1. In Deafult Project, select Pipelines.
  2. Select Create a Pipeline and enter the following details:
    • In Name, enter harness_guestbook_pipeline.
    • In How do you want to setup your pipeline?, select Inline.
    • Select Start and toggle to the YAML view (next to VISUAL).
  3. Select Edit YAML to enable edit mode, and then select any of the following execution strategies. Paste the respective YAML based on your selection.
What are Canary deployments?

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. For more information, go to When to use Canary deployments.

  • Copy the contents of 6-canary-deployment.yml and paste it in the YAML editor.
  • Select Save to save the pipeline.
  • You can switch to the VISUAL view, and verify that the pipeline stage and execution steps appear as shown below.

Canary

Run the pipeline

Finally, it's time to execute the pipeline.

  1. 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

Congratulations!🎉

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

Next steps