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 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 dev / test / stage / prod clusters, while running a variety of scans & tests to ensure quality and stability standards you and team may have defined.

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 through the GitHub website.
    • For details on Forking a GitHub repository, go to GitHub docs for more information on forking a GitHub repository.

Getting Started with Harness CD

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

For the pipeline to run successfully, please follow the remaining steps as they are, including the naming conventions.

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.

  1. Under Project Setup, select Delegates.

    • Select New Delegate.

      For this tutorial, let's explore how to install a delegate using Helm.

      • Add the Harness Helm chart repo to your local helm registry using the following commands.
      helm repo add harness-delegate https://app.harness.io/storage/harness-download/delegate-helm-chart/
      • Update the repo:
      helm repo update harness-delegate
      • In the example command provided, ACCOUNT_ID and MANAGER_ENDPOINT are auto-populated values that you can obtain from the delegate installation wizard.
      • Copy the command as shown in the installation wizard, which is of the format of the example mentioned below and run in your terminal.
      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_TOKEN
      • Select Verify to 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 Harness Terraform Provider or a Kubernetes manifest.

Secrets

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.

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

Connectors

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.

  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 harness_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 harness_k8sconnector is successfully created.
    • Finally, select Connection Test under Connectivity Status to verify the connection is successful.

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.

  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

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.

  1. In your Harness project, select Services.
    • Select New Service.
    • Enter the name harnessguestbook.
    • 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 harness_guestbook is successfully created.

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.

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.

  • 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.
  1. Copy the contents of canary-pipeline.yml.

  2. In your Harness pipeline YAML editor, paste the YAML.

  3. Select Save.

    You can switch to the Visual editor and confirm the pipeline stage and execution steps as shown below.

Manually execute deployment pipelines

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

  1. 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 by the Harness pipeline, port forward the service and access it at http://localhost:8080

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

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 an application using a Kubernetes manifest.

Continue your learning journey by learning about variables and pipeline triggers.

How to deploy your own app by using Harness

You can integrate your own microservice application into this tutorial by following the steps outlined below:

  • Utilize the same delegate that you deployed as part of this tutorial. Alternatively, deploy a new delegate, but remember to use a newly created delegate identifier when creating connectors.

  • If you intend to use a private Git repository that hosts your manifest files, create a Harness secret containing the Git personal access token (PAT). Subsequently, create a new Git connector using this secret.

  • Create a Kubernetes connector if you plan to deploy your applications in a new Kubernetes environment. Make sure to update the infrastructure definition to reference this newly created Kubernetes connector.

  • Once you complete all the aforementioned steps, create a new Harness service that leverages Kubernetes manifests for deploying applications.

  • Lastly, establish a new deployment pipeline and select the newly created infrastructure definition and service. Choose a deployment strategy that aligns with your microservice application's deployment needs.

  • Voila! You're now ready to deploy your own application by using Harness.