Skip to main content

Deploy using Kubernetes Manifest

Last updated on

This topic explains how to deploy a sample application (Guestbook) using a publicly available Kubernetes manifest and Docker image with Harness Continuous Delivery (CD).

Harness CD offers two ways to deploy the Guestbook application:

  • CD pipeline: You build a Harness pipeline that deploys the manifest 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:


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

Run the following command 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)

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 the Guestbook 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.
warning

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

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, and so on. The delegate is installed in the target infrastructure, for example, a Kubernetes cluster, and performs operations including deployment and integration. Go to Delegate Overview to understand the delegate.

Perform the following steps to set up a delegate:

  1. Under Project Settings, select Delegates.

  2. Click New Delegate.

  3. Select Kubernetes in the Select where you want to install your Delegate section.

  4. In the Install your Delegate section, for this tutorial, install the delegate using Helm Chart.

  5. Add the Harness Helm chart repo to your local helm registry using the following command.

    helm repo add harness-delegate https://app.harness.io/storage/harness-download/delegate-helm-chart/
  6. Update the repo using the following command:

    helm repo update harness-delegate
  7. Copy and run the install command from the Delegate installation wizard as shown in the following example:

    Here, the ACCOUNT_ID, MANAGER_ENDPOINT and DELEGATE_TOKEN are auto-populated values you will get from the wizard itself.

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

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 Settings, select Secrets.
  2. Click New Secret, and then select Text.
  3. In the Add new Encrypted Text page,
    1. Select the Secret Manager. For example, Harness Built-in Secret Manager.
    2. Enter the Secret Name. For example, harness_gitpat.
    3. For the Secret Value, paste the GitHub personal access token you saved earlier.
    4. Add the Description (Optional) and Tags (Optional).
    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 Settings, select Connectors.
  3. Select Create via YAML Builder and paste the copied YAML in Step 1.
  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 suggests the correct Id.
  6. Select Save Changes and verify that the new connector named harness_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 Settings, select Connectors.
  3. Select Create via YAML Builder and paste the copied YAML in Step 1.
  4. Replace DELEGATE_NAME with the installed Delegate name. To obtain the Delegate name, navigate to Project Settings, and then Delegates.
  5. Select Save Changes and verify that the new connector named harness_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, under Project Settings, select Environments.
  2. Click New Environment.
  3. In the New Environment page,
    1. Select YAML.
    2. Copy the contents of environment.yml, paste it into the YAML editor.
    3. Select Save.
  4. In your new environment, select the Infrastructure Definitions tab.
  5. Select Infrastructure Definition.
  6. In the Create New Infrastructure page,
    1. Select YAML.
    2. Copy the contents of infrastructure-definition.yml and paste it into the YAML editor.
    3. 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, under Project Settings, select Services.
  2. Select New Service.
  3. On the Add Service page,
    1. Enter the service name. For example, harnessguestbook.
    2. Select Save.
    3. On the Configuration tab, select YAML option.
    4. Select Edit YAML, copy the contents of service.yml, and paste it into the YAML editor.
    5. Select Save. Verify that the service harness_guestbook 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:

Rolling deployments incrementally add nodes in a single environment with a new service version, either one-by-one or in batches defined by a window size. Rolling deployments allow a controlled and gradual update process for the new service version. Go to When to use rolling deployments to understand when to use them.

Perform the following steps to set up a pipeline with rolling deployment:

  1. In Default Project, select Pipelines.
  2. Select Create a Pipeline.
  3. In the Create new Pipeline page,
    1. Enter the name. For example, guestbook_rolling_pipeline.
    2. Enter a description (optional).
    3. Enter a tag (optional).
    4. Specify the YAML version. For example, v0.
    5. Select Inline to store the pipeline in Harness.
    6. Select Start with Template to create the pipeline with an existing template in Harness Manager.
    7. Select Start.
  4. In the Pipeline Studio, toggle to YAML to use the YAML editor.
  5. Select Edit YAML to enable edit mode.
  6. Copy the contents of rolling-pipeline.yml.
  7. In your Harness pipeline YAML editor, paste the YAML.
  8. Select Save.

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

Rolling deployment pipeline

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. After configuring the pipeline, select Run 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 default
  4. 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

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.

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

Deploy your own application

You can use your own microservice application with this tutorial by following the steps below:

  • Use 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. Ensure 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 uses Kubernetes manifests for deploying applications.

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


Next steps

You have deployed the Guestbook application with Harness CD and GitOps using a Kubernetes manifest.

Continue your learning journey with the following: