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.
- CD pipeline
- GitOps workflow
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.
Before you begin
Verify that you have the following:
- Obtain GitHub personal access token with the repo scope. See the GitHub documentation on creating a personal access token.
- 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.
- Check Delegate system requirements.
- Install the Helm CLI in order to install the Harness Helm delegate.
- Fork the harnessed-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
- Login to Harness.
- Select Projects, and then select Default Project.
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.
Under Project Setup, select Delegates.
Select Tokens.
- Select New Token.
- Name the token
delegate_token
. - Select Apply.
- Copy the token value by selecting on the copy icon and store it somewhere.
- Select Close.
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 command provided,
ACCOUNT_ID
andMANAGER_ENDPOINT
are auto-populated values that you can obtain from the delegate installation wizard.Replace DELEGATE_TOKEN in the command with the token that was copied earlier and proceed with delegate installation.
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_TOKENSelect Verify to 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 tutorial 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.
- 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.
- 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 harnessed-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 (afteraccount
). 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.
- 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.
- 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.
- 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 the 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.
- Canary
- Blue Green
- Rolling
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.
Copy the contents of canary-pipeline.yml.
In your Harness pipeline YAML editor, paste the YAML.
Select Save.
You can switch to the Visual editor and confirm the pipeline stage and execution steps as shown below.
What are Blue Green deployments?
Blue Green deployments involve running two identical environments (stage and prod) simultaneously with different service versions. QA and UAT are performed on a new service version in the stage environment first. Next, traffic is shifted from the prod environment to stage, and the previous service version running on prod is scaled down. Blue Green deployments are also referred to as red/black deployment by some vendors. For more information, go to When to use Blue Green deployments.
- In Default Project, select Pipelines.
- Select New Pipeline.
- Enter the name
guestbook_bluegreen_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.
Copy the contents of bluegreen-pipeline.yml.
In your Harness pipeline YAML editor, paste the YAML.
Select Save.
You can switch to the Visual pipeline editor and confirm the pipeline stage and execution steps as shown below.
What are Rolling deployments?
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. For more information, go to When to use rolling deployments.
- In Default Project, select Pipelines.
- Select New Pipeline.
- Enter the name
guestbook_rolling_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.
Copy the contents of rolling-pipeline.yml.
In your Harness pipeline YAML editor, paste the YAML.
Select Save.
You can switch to the Visual pipeline editor and confirm the pipeline stage and execution steps as shown below.
Finally, it's time to execute your pipeline.
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
Congratulations!🎉
You've just learned how to use Harness CD to deploy an application using a Kubernetes manifest.
What's Next?
- Keep learning about Harness CD. For example, add Triggers to your pipeline that initiate pipeline deployments in response to Git events.
- Visit the Harness Developer Hub for more tutorials and resources.
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.
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:
- A Kubernetes cluster. We recommend K3D for installing the Harness GitOps Agent and deploying a sample application in a local development environment.
- For requirements, go to Harness GitOps Agent Requirements.
- Fork the harnessed-example-apps repository through the GitHub web interface.
- For details on Forking a GitHub repository, go to GitHub docs.
Getting Started with Harness GitOps
- Login to Harness.
- Select Projects, and then select Default Project.
- Select Deployments, and then select GitOps.
GitOps Agent
What is a GitOps Agent?
- 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.
- Harness GitOps Agent Fresh Install
- Harness GitOps Agent with existing Argo CD instance
- 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.
- For this tutorial, let's use the
- 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.
```yaml
kubectl apply -f gitops-agent.yml -n default
```
- Select Continue and verify the Agent is successfully installed and can connect to Harness Manager.
Select Yes, and then select Start.
In Name, enter the name for the existing Argo CD project.
In Namespace, enter the namespace where you want to install the Harness GitOps Agent. Typically, this is the target namespace for your deployment.
Select Next. 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
Once you have installed the Agent, Harness will start importing all the entities from the existing Argo CD Project.
Repositories
What is a GitOps Repository?
- 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?
- 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.
- Select New Cluster.
Applications
What is a GitOps Application?
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: trueSelect 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.
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.
Congratulations!🎉
You've just learned how to use Harness GitOps to deploy application using a Kubernetes manifest.
What's Next?
- Keep learning about Harness GitOps. Create a GitOps ApplicationSet and PR Pipeline in Harness GitOps by following this guide.
- Visit the Harness Developer Hub for more tutorials and resources.