Skip to main content

Deploy your own microservice application

This tutorial is a continuation of the Kubernetes Manifest tutorial. In that tutorial, we guided you through creating a sample pipeline using the Guestbook sample app. In this tutorial, we'll walk you through deploying your own microservice app with the Harness CD pipeline or GitOps workflow.

You can use the same steps to integrate and deploy your own microservice app.

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

Before you begin

Verify that you have the following:

  1. Obtain GitHub personal access token with the repo scope. See the GitHub documentation on creating a personal access token.
  2. A Kubernetes cluster. Use your own Kubernetes cluster or we recommend using K3D for installing Harness Delegates and deploying a sample application in a local development environment.
  3. Install the Helm CLI in order to install the Harness Helm delegate.
  4. Fork the harnesscd-example-apps repository using the GitHub web interface to utilize the Harness resource YAMLs.

Getting Started with Harness CD

  1. Log in to Harness.
  2. Select Projects, and then select Default Project.

Delegate

  1. 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.
  • Log in to the Harness UI. In Project Setup, select Delegates.

    • Select Delegates.

      • Select Install delegate. For this tutorial, let's explore how to install the delegate using Helm.
      • 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/
      helm repo update harness-delegate
      • In the command provided, ACCOUNT_ID, MANAGER_ENDPOINT, and DELEGATE_TOKEN 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:24.12.84702 \
        --set replicas=1 --set upgrader.enabled=true \
        --set delegateToken=DELEGATE_TOKEN
    • Verify that the delegate is installed successfully and can connect to the Harness Manager.

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

warning

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

Secrets

  1. Under Project Setup, select Secrets.
    • Select New Secret, and then select Text.
    • Enter the secret name ownappgitpat.
    • For the secret value, paste the GitHub personal access token you saved earlier.
    • Select Save.

Connectors

  1. Create the GitHub connector.
    • Copy the contents of github-connector.yml.
    • In your Harness project in the Harness Manager, under Project Setup, select Connectors.
    • Select Create via YAML Builder and paste the copied YAML.
    • Assuming you have already forked the harnesscd-example-apps repository mentioned earlier, replace GITHUB_USERNAME with your GitHub account username in the YAML.
    • 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.
    • Select Save Changes and verify that the new connector named ownapp_gitconnector is successfully created.
    • Finally, select Connection Test under Connectivity Status to ensure the connection is successful.
  2. Create the Kubernetes connector.
    • Copy the contents of kubernetes-connector.yml.
    • In your Harness project, under Project Setup, select Connectors.
    • Select Create via YAML Builder and and paste the copied YAML.
    • Replace DELEGATE_NAME with the installed Delegate name. To obtain the Delegate name, navigate to Project Setup, and then Delegates.
    • Select Save Changes and verify that the new connector named ownapp_k8sconnector is successfully created.
    • Finally, select Connection Test under Connectivity Status to verify the connection is successful.

Environment

  1. In your Harness project, select Environments.
    • Select New Environment, and then select YAML.
    • Copy the contents of environment.yml, paste it into the YAML editor, and select Save.
    • In your new environment, select the Infrastructure Definitions tab.
    • Select Infrastructure Definition, and then select YAML.
    • Copy the contents of infrastructure-definition.yml and paste it into the YAML editor.
    • Select Save and verify that the environment and infrastructure definition are created successfully.

Services

  1. In your Harness project, select Services.
    • Select New Service.
    • Enter the name ownappservice.
    • Select Save, and then YAML (on the Configuration tab).
    • Select Edit YAML, copy the contents of service.yml, and paste it into the YAML editor.
    • Select Save, and verify that the service ownapp_service is successfully created.

Pipeline

  1. In Default Project, select Pipelines.
    • Select New Pipeline.
    • Enter the name ownapp_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.
      • Copy the contents of canary-pipeline.yml.
      • In your Harness pipeline YAML editor, paste the YAML.
      • Select Save.

Manually execute deployment pipelines

Finally, it's time to execute your pipeline. Every exection of a CD pipeline leads to a deployment.

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

Automate deployments

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 utilize the Harness API to manage resources, view, create/edit, or delete them.

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

Congratulations!🎉

You've just learned how to use Harness CD to deploy your own application.