Skip to main content

Deploy using Kubernetes Manifest

This tutorial will get you started with Harness Continuous Delivery (CD). We will guide you through deploying a Guestbook application using Harness CD pipeline and GitOps methods. This Guestbook application uses a publicly available Kubernetes manifest and Docker image.

info

Kubernetes is required to complete these steps. Run the following to check your system resources and (optionally) install a local cluster.

bash <(curl -fsSL https://raw.githubusercontent.com/harness-community/scripts/main/delegate-preflight-checks/cluster-preflight-checks.sh)

Harness GitOps (built on top of Argo CD) watches the state of your application as defined in a Git repo, and can pull (either automatically, or when instructed to do so) these changes into your Kubernetes cluster, leading to an application sync.

info

Whether you're new to GitOps or have already used Argo CD, this guide will assist you in getting started with Harness GitOps, both with and without Argo CD.

Before you begin

Verify that you have the following:

  1. A Kubernetes cluster. We recommend K3D for installing the Harness GitOps Agent and deploying a sample application in a local development environment.
  2. Fork the harnesscd-example-apps repository through the GitHub web interface.
    • For details on Forking a GitHub repository, go to GitHub docs.

Getting Started with Harness GitOps


  1. Login to Harness.
  2. Select Projects, and then select Default Project.
  3. Select Deployments, and then select GitOps.

GitOps Agent

What is a GitOps Agent?
A Harness GitOps Agent is a worker process that runs in your environment, makes secure, outbound connections to Harness, and performs all the GitOps tasks you request in Harness.
  1. Select Settings, and then select GitOps Agents.
    • Select New GitOps Agent.
    • When are prompted with Do you have any existing Argo CD instances?, select Yes if you already have a Argo CD Instance, or else choose No to install the Harness GitOps Agent.
  • 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 will 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 the Agent is successfully installed and can connect to Harness Manager.

Repositories

What is a GitOps Repository?
A Harness GitOps Repository is a repo containing the declarative description of a desired state. The declarative description can be in Kubernetes manifests, Helm Chart, Kustomize manifests, etc.
  1. Select Settings, and then select Repositories.
    • Select New Repository.
    • Choose Git.
      • Enter a name in Repository.
      • In GitOps Agent, select the Agent that you installed in your cluster and select Apply.
      • In Git Repository URL, paste https://github.com/GITHUB_USERNAME/harnesscd-example-apps and replace GITHUB_USERNAME with your GitHub username.
      • Select Continue and choose Specify Credentials For Repository.
        • Select HTTPS as the Connection Type.
        • Select Anonymous (no credentials required) as the Authentication method.
        • Select Save & Continue and wait for Harness to verify the connection.
        • Finally, select Finish.

Clusters

What is a GitOps Cluster?
A Harness GitOps Cluster is the target deployment cluster that is compared to the desire state. Clusters are synced with the source manifests you add as GitOps Repositories.
  1. Select Settings, and then select Clusters.
    • Select New Cluster.
      • In Name, enter a name for the cluster.
      • In GitOps Agent, select the Agent you installed in your cluster, and then select Apply.
      • Select Continue and select Use the credentials of a specific Harness GitOps Agent.
      • Select Save & Continue and wait for the Harness to verify the connection.
      • Finally, select Finish.

Applications

What is a GitOps Application?
GitOps Applications are how you manage GitOps operations for a given desired state and its live instantiation. A GitOps Application collects the Repository (**what you want to deploy**), Cluster (**where you want to deploy**), and Agent (**how you want to deploy**). You select these entities when you set up your Application.
  1. Select Applications.

    • Select New Application.

      • Enter the Application Name: guestbook.

      • In GitOps Agent, select the Agent that you installed in your cluster and select Apply.

      • Select New Service, and then toggle to YAML to use the YAML editor.

      • Select Edit YAML, paste in the YAML below, and then select Save.

        service:
        name: gitopsguestbook
        identifier: gitopsguestbook
        serviceDefinition:
        type: Kubernetes
        spec: {}
        gitOpsEnabled: true
      • Select New Environment, and the toggle to YAML to use the YAML editor.

      • Select Edit YAML, paste in the YAML below, and then select Save.

        environment:
        name: gitopsenv
        identifier: gitopsenv
        description: ""
        tags: {}
        type: PreProduction
        orgIdentifier: default
        projectIdentifier: default_project
        variables: []
      • Next, select Continue, keep the Sync Policy settings as is, and select Continue.

      • In Repository URL, select the Repository you created earlier, and then select Apply.

      • Select master as the Target Revision, type guestbook in the Path, and then select Enter.

      • Select Continue and select the Cluster created in the above steps.

      • In Namespace, enter the target namespace for Harness GitOps to sync the application.

      • Enter default and select Finish.

  2. Finally, it's time to Synchronize the GitOps Application state. Select Sync, 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:

      kubectl port-forward svc/guestbook-ui 8080:80

A successful Application sync will display the following status tree under Resource View.

GitOps


Congratulations!🎉

You've just learned how to use Harness GitOps to deploy an application using a Kubernetes manifest.

What's Next?