InformationContinue your learning journey.Take a Continuous Delivery & GitOps Certification today!
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.

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. Harness GitOps supports both Argo CD and Flux CD as the GitOps reconciler.

Whether you're new to GitOps or an experienced practitioner, this guide will assist you in getting started with Harness GitOps, offering you the option to choose between Argo CD and Flux 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 GitOps Operator, select one of the following:
    • Argo. Uses Argo CD as the GitOps reconciler.
    • Flux. Uses Flux as the GitOps reconciler.
  • In Namespace, enter the namespace where you want to install the Harness GitOps Agent.

Harness GitOps Agent will have access to create or modify resources in other namespaces so this namespace doesn't necessarily have to be the same as the one where your apps are deployed. For instance, you can choose argocd or fluxcd as the namespace for installing the GitOps Agent (the example in the image below uses gitops-agent as the namespace). Ensure that this namespace already exists on your Kubernetes cluster.

If Namespaced is selected, the Harness GitOps agent is installed without cluster-scoped permissions, and it can access only those resources that are in its own namespace. You can select Skip Crds to avoid a collision if already installed.

  • Select Continue. The Download YAML or Download Helm Chart settings appear.

Download YAML or Helm chart setting

Download the Harness GitOps Agent script using either the YAML or Helm Chart options. The YAML option provides a manifest file, and the Helm Chart option offers a Helm chart file. Both can be downloaded and used to install the GitOps agent on your Kubernetes cluster. The third step includes the command to run this installation.

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

note

If you're using a Flux GitOps Reconciler, Flux must be present in the destination cluster. As of now, this limits us to in-cluster type applications.

  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.

note

If you're using a Flux GitOps Reconciler, Flux must be present in the destination cluster. As of now, this limits us to in-cluster type applications.

  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.

note

Due to an update in the Kustomization Controller, the vanilla YAML files now need to include a namespace. The specific repository and path used in this example include the namespace field in the YAMLs.

  1. Select Applications.

    • Select New Application.
      • Enter the Application Name: guestbook.
      • In GitOps Operator, select either Argo or Flux. Based on your selection, the associated GitOps Agent will be listed next.
      • In GitOps Agent, select the Agent that you installed in your cluster.
      • You can leave out Service and Environment selections.
      • Select Continue.
    • Under Sync Policy
      • Make sure Apply Out of Sync Only and Auto-Create Namespace are checked under Sync Options settings.
      • Use Foreground for the Prune Propagation Policy.
      • Select Continue.
    • Under Source
      • Select the repository you created earlier for the Repository URL.
      • Select master as the Target Revision.
      • Use workshop-guestbook for the Path.
      • Select Continue.
    • Under Destination
      • Select the cluster you previously created under Cluster.
      • For Namespace, enter guestbook. This is the target namespace for Harness GitOps to sync the application.
      • 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 guestbook
    • 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 -n guestbook

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.

Continue your learning journey by learning about variables,pipeline triggers, and Harness GitOps.