Skip to main content

Deploy your own microservice application

Last updated on

This topic explains how to deploy your own microservice application with Harness Continuous Delivery (CD). It continues from the Kubernetes Manifest tutorial, which deploys the Guestbook sample application.

Harness CD offers two ways to deploy your application:

  • CD pipeline: You build a Harness pipeline that deploys your application 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. If you completed the Kubernetes Manifest tutorial, you can reuse its delegate and other resources.

  • GitHub personal access token: A token with the repo scope. Go to creating a personal access token to generate one.
  • Kubernetes cluster: Use your own cluster, or install K3D to run Harness Delegates and the application in a local development environment. Go to Delegate system and network requirements to review the requirements.
  • Helm CLI: Install the Helm CLI to install the Harness Helm delegate.
  • Forked example repository: Fork the harnesscd-example-apps repository through the GitHub web interface to use the Harness resource YAMLs.
  • Harness API token (CLI or Terraform method only): A token required to run the CLI or Terraform steps. Go to creating a personal API token to generate one.

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 your application using either a Harness CD pipeline or a Harness GitOps workflow.

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 your application using the 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.

Delegate

You have the option to use the same delegate that you deployed during the Manifest tutorial, or to deploy a new delegate by following the steps below. However, remember to use a newly created delegate identifier when creating connectors.

Perform the following steps to set up a new delegate:

  1. Log in to the Harness UI. In Project Setup, select Delegates.
  2. Select Delegates, and then select Install delegate. For this tutorial, install the delegate using Helm.
  3. Add the Harness Helm chart repo to your local Helm registry.
    helm repo add harness-delegate https://app.harness.io/storage/harness-download/delegate-helm-chart/
  4. Update the repo using the following command:
    helm repo update harness-delegate
  5. In the command provided, ACCOUNT_ID, MANAGER_ENDPOINT, and DELEGATE_TOKEN are auto-populated values that you can obtain from the delegate installation wizard. Run the install command:
    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:24.12.84702 \
    --set replicas=1 --set upgrader.enabled=true \
    --set delegateToken=DELEGATE_TOKEN
  6. 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 Terraform Helm Provider or a Kubernetes manifest.

warning

If you plan to use your own Project, Organization, and custom names for Harness resources, update the resource YAMLs accordingly with these details.

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 Setup, select Secrets.
  2. Select New Secret, and then select Text.
  3. Enter the secret name ownappgitpat.
  4. For the secret value, paste the GitHub personal access token you saved earlier.
  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. Copy the contents of github-connector.yml.
  2. In your Harness project in the Harness Manager, under Project Setup, select Connectors.
  3. Select Create via YAML Builder and paste the copied YAML.
  4. 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).
  5. 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 will suggest the correct Id.
  6. Select Save Changes and verify that the new connector named ownapp_gitconnector is successfully created.
  7. 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. Copy the contents of kubernetes-connector.yml.
  2. In your Harness project, under Project Setup, select Connectors.
  3. Select Create via YAML Builder and paste the copied YAML.
  4. Replace DELEGATE_NAME with the installed Delegate name. To obtain the Delegate name, navigate to Project Setup, and then Delegates.
  5. Select Save Changes and verify that the new connector named ownapp_k8sconnector is successfully created.
  6. Select Connection Test under Connectivity Status to verify the connection is successful.

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 your Harness project, select Environments.
  2. Select New Environment, and then select YAML.
  3. Copy the contents of environment.yml, paste it into the YAML editor, and select Save.
  4. In your new environment, select the Infrastructure Definitions tab.
  5. Select Infrastructure Definition, and then select YAML.
  6. Copy the contents of infrastructure-definition.yml and paste it into the YAML editor.
  7. Select Save and verify that the environment and infrastructure definition are created successfully.

Services

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 your Harness project, select Services.
  2. Select New Service and enter the name ownappservice.
  3. Select Save, and then select YAML on the Configuration tab.
  4. Select Edit YAML, copy the contents of service.yml, and paste it into the YAML editor.
  5. Select Save and verify that the service ownapp_service 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.

Pick a deployment strategy from the following:

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 ownapp_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 canary-pipeline.yml, and paste it into the YAML editor.
  7. Select Save.

Execute the deployment pipelines

You can execute the pipeline deployment using any of the following:

  • Manual - Start the pipeline on demand from the Harness UI whenever you want to perform a deployment.
  • Automatic - Configure a trigger so the pipeline runs automatically in response to events such as Git commits, pull requests, or webhook notifications.

Every execution of a CD pipeline results in a deployment to the target environment.

Manual deployment

Perform the following steps to manually execute the deployment:

  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 harness-delegate-ng

Automatic deployment

Using Triggers

With Pipeline Triggers, you can start automating your deployments based on events happening in an external system. This system could be a Source Repository, an Artifact Repository, or a third party system. Any Developer with Pipeline Create and Edit permissions can configure a trigger in Harness.

Follow the Pipeline Triggers tutorial to see triggers in action.

Using API

You can also use the Harness API to manage resources, view, create/edit, or delete them.

Go to the Get started with Harness API guide to learn how to use the API for automation.


Next steps

You have deployed your own microservice application with Harness CD and GitOps.

Continue your learning journey with the following: