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.

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

    • 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
    • Copy the following command from the Delegate Installation wizard.

      DELEGATE_TOKEN,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 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 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.

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.

How Harness performs canary and blue-green deployments with Helm
  • Harness integrates with Helm by utilizing 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 a streamlined and automated approach to canary and blue-green deployments. By leveraging Helm's package management capabilities and integrating with its release management features, Harness extends Helm's capabilities to support canary and blue-green deployment strategies.

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.

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 k8s-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 k8s-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, harnessguestbookdep, 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 k8s-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.

  • In Default Project, select Pipelines.
    • Select New Pipeline.
    • Enter the name guestbook_canary_pipeline.
    • Select Inline to store the pipeline in Harness.
    • Select Start and, in the Pipeline Studio, toggle to YAML to use the YAML editor.
    • Select Edit YAML to enable edit mode, and copy the contents of k8s-canary-pipeline.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

How to deploy your own app by using Harness

You can integrate your own microservice application into this tutorial by following the steps outlined below:

  • Utilize 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. Make sure 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.

  • Lastly, 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.

  • Voila! You're now ready to deploy your own application by using Harness.

Congratulations!🎉

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

Next steps