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.
- CD Pipeline
- GitOps Workflow
Before you begin
Make sure that you have met the following requirements:
- You have a GitHub Personal Access Token (PAT) with proper repository permissions. For more information, go to Managing your personal access token.
- You have set up a Kubernetes cluster. You can use your own Kubernetes cluster or a K3D (recommended) for installing Harness Delegates and deploying a sample application in a local development environment. For more information, go to Delegate system and network requirements.
- You have installed Helm CLI.
- You have forked the harnessed-example-apps repository through the GitHub web interface. For more details, go to Forking a GitHub repository.
Deploy your applications using a Helm template
Log in to the Harness App.
Select Projects on the top left corner of the UI, and then select Default Project.
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.
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
andMANAGER_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_TOKENVerify 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.
- In PROJECT SETUP, select Secrets.
- Select New Secret, and then select Text.
- In the Add new Encrypted Text dialog:
- In Secret Name, enter
harness_gitpat
. - In Secret Value, enter your GitHub PAT.
- In Secret Name, enter
- 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.
- Create a GitHub connector.
- In PROJECT SETUP, select Connectors, and then select Create via YAML Builder.
- Copy and paste the contents of github-connector.yml.
- 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.
- Select Save Changes, and verify that the new connector named harness_gitconnector is successfully created.
- Select Connection Test under Connectivity Status to ensure that the connection is successful.
- Create a Kubernetes connector.
- In PROJECT SETUP, select Connectors, and then select Create via YAML Builder.
- Copy and paste the contents of kubernetes-connector.yml.
- Replace DELEGATE_NAME with the installed delegate name. To obtain the delegate name, navigate to Default Project > PROJECT SETUP > Delegates.
- Select Save Changes, and verify that the new connector named harness_k8sconnector is successfully created.
- 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.
- Canary
- Blue Green
- Rolling
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.
- In Default Project, select Environments.
- Select New Environment and toggle to the YAML view (next to VISUAL).
- Copy the contents of environment-blucan.yml and paste it in the YAML editor, and then select Save.
- In the Infrastructure Definitions tab, select Infrastructure Definition, and then select Edit YAML.
- Copy the contents of infrastructure-definition-blucan.yml and paste it in the YAML editor.
- 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.
- In Default Project, select Services.
- Select New Service, enter the name,
harnessguestbookdep
, and then select Save. - Toggle to the YAML view (next to VISUAL) under the Configuration tab, and then select Edit YAML.
- Copy the contents of service-blucan.yml and paste it in the YAML editor.
- 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 choose any of the following execution strategies. Paste the respective YAML based on your selection.
Copy the contents of 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.
What are Blue Green deployments?
Blue Green deployments involve running two identical environments (stage and prod) simultaneously with different service versions. QA and UAT are performed on a new service version in the stage environment first. Next, traffic is shifted from the prod environment to stage, and the previous service version running on prod is scaled down. Blue Green deployments are also referred to as red/black deployment by some vendors. For more information, go to When to use Blue Green 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.
- In Default Project, select Environments.
- Select New Environment and toggle to the YAML view (next to VISUAL).
- Copy the contents of environment-blucan.yml and paste it in the YAML editor, and then select Save.
- In the Infrastructure Definitions tab, select Infrastructure Definition, and then select Edit YAML.
- Copy the contents of infrastructure-definition-blucan.yml and paste it in the YAML editor.
- 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.
- In Default Project, select Services.
- Select New Service, enter the name,
harnessguestbookdep
, and then select Save. - Toggle to the YAML view (next to VISUAL) under the Configuration tab, and then select Edit YAML.
- Copy the contents of service-blucan.yml and paste it in the YAML editor.
- 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_bluegreen_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 choose any of the following execution strategies. Paste the respective YAML based on your selection.
Copy the contents of bluegreen-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.
What are Rolling deployments?
Rolling deployments incrementally add nodes in a single environment with a new service version, either one-by-one or in batches defined by a window size. Rolling deployments allow a controlled and gradual update process for the new service version. For more information, go to When to use rolling 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.
- In Default Project, select Environments.
- Select New Environment and toggle to the YAML view (next to VISUAL).
- Copy the contents of environment-rolling.yml and paste it in the YAML editor, and then select Save.
- In the Infrastructure Definitions tab, select Infrastructure Definition, and then select Edit YAML.
- Copy the contents of infrastructure-definition-rolling.yml and paste it in the YAML editor.
- 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.
- In Default Project, select Services.
- Select New Service, enter the name,
harnessguestbook
, and then select Save. - Toggle to the YAML view (next to VISUAL) under the Configuration tab, and then select Edit YAML.
- Copy the contents of service-rolling.yml and paste it in the YAML editor.
- 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_rolling_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 choose any of the following execution strategies. Paste the respective YAML based on your selection.
Copy the contents of rolling-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.
Run the pipeline
Finally, it's time to execute the pipeline.
Select Run, and then select Run Pipeline to initiate the deployment.
Observe the execution logs as Harness deploys the workload and checks for steady state.
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 using the Harness pipeline, port forward the service and access it at
http://localhost:8080
:kubectl port-forward svc/<service-name> 8080:80
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:
- You have set up a Kubernetes cluster. We recommend using K3D for installing Harness Delegates and deploying a sample application in a local development environment. For more information, go to Delegate system and network requirements.
- You have forked the harnessed-example-apps repository through the GitHub web interface. For more details, go to Forking a GitHub repository.
Deploy your applications uisng Harness GitOps
Log in to the Harness App.
Select Projects in the top left corner of the UI, and then select Default Project.
In Deployments, select GitOps.
Install a Harness GitOps Agent
What is a GitOps Agent?
- Select Settings on the top right corner of the UI.
- Select GitOps Agents, and then select New GitOps Agent.
- 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.
- Harness GitOps Agent Fresh Install
- Harness GitOps Agent with Existing Argo CD Instance
- In Do you have any existing Argo CD instances?, select No, and then select Start.
- In Name, enter the name for the new Agent.
- 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. - 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
- Select Continue and verify that the Agent is successfully installed and can connect to Harness Manager.
- In Do you have any existing Argo CD instances?, select Yes, and then select Start.
- In Name, enter the name of the existing Argo CD project.
- 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. - 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
- Select Continue and verify that the Agent is successfully installed and can connect to Harness Manager.
Once you have installed the Agent, Harness will start importing all the entities from the existing Argo CD Project.
Add a Harness GitOps repository
What is a GitOps Repository?
- Select Settings in the top right corner of the UI.
- Select Repositories, and then select New Repository
- Select Git and enter the following details:
- In Repository Name, enter the Git repository name.
- In GitOps Agent, choose the Agent that you installed in your cluster and select Apply.
- In Git Repository URL, enter
https://github.com/GITHUB_USERNAME/harnesscd-example-apps.git
and replace GITHUB_USERNAME with your GitHub username.
- Select Continue and choose Specify Credentials For Repository.
- In Connection Type, select HTTPS.
- In Authentication, select Anonymous (no credentials required).
- Select Save & Continue and wait for Harness to verify the conenction.
- Select Finish.
Add a Harness GitOps cluster
What is a GitOps Cluster?
- Select Settings in the top right corner of the UI.
- Select Clusters, and then select New Cluster.
- In the cluster Overview dialog, enter a name for the cluster.
- In GitOps Agent, select the Agent that you installed in your cluster and select Apply.
- Select Continue and select Use the credentials of a specific Harness GitOps Agent.
- Select Save & Continue and wait for Harness to verify the conenction.
- Select Finish.
Add a Harness GitOps application
What is a GitOps Application?
Select Applications on the top right corner of the UI.
Select New Application.
In Application Name, enter the name,
guestbook
.In GitOps Agent, select the Agent that you installed in your cluster and select Apply.
Select New Service and toggle to the YAML view (next to VISUAL).
Select Edit YAML, and then paste the following, and select Save.
service:
name: gitopsguestbook
identifier: gitopsguestbook
serviceDefinition:
type: Kubernetes
spec: {}
gitOpsEnabled: trueSelect New Environment and toggle to the YAML view (next to VISUAL).
Select Edit YAML, and then paste the following, and select Save
environment:
name: gitopsenv
identifier: gitopsenv
description: ""
tags: {}
type: PreProduction
orgIdentifier: default
projectIdentifier: default_project
variables: []Select Continue, keep the Sync Policy settings as is, and then select Continue.
In Repository URL, select the Repository you created earlier and select Apply.
Select master as the target Revision and enter
kustomize-guestbook
in the Path and hit enter.Select Continue to select the Cluster created in the above steps.
Enter the target Namespace for Harness GitOps to sync the application. Enter
default
and select Finish
Sync the application
Finally, it's time to Synchronize the application state.
- Select Sync in the top right corner of the UI.
- 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
:```bash
kubectl port-forward svc/<service-name> 8080:80
```On successful application sync, you'll see the status tree under Resource View as shown below:
Congratulations!🎉
You've just learned how to use Harness CD to deploy application using a Helm Chart template.
Next steps
- Keep learning about Harness CD. Add Triggers to your pipeline that'll respond to Git events. For more information, go to Triggering pipelines.
- Visit Harness Developer Hub for more tutorials and resources.