Harness CLI Examples
In this segment, we'll guide you through a example demonstrating how to utilize the Harness CLI tool. You have the option to either establish a Harness GitOps workflow or configure a pipeline along with all necessary components to deploy a test guestbook application to your Kubernetes setup.
Let's Begin
- GitOps Example
- CD Pipeline Example
-
Refer Install and Configure Harness CLI doc to setup and configure Harness CLI.
-
Fork the harnesscd-example-apps repository through the GitHub web interface.
-
Clone the Forked harnesscd-example-apps repo and change directory.
git clone https://github.com/GITHUB_ACCOUNTNAME/harnesscd-example-apps.git
cd harnesscd-example-appsnoteReplace
GITHUB_ACCOUNTNAME
with your GitHub Account name. -
Make sure you have a GitOps Agent configured and running smoothly. If not, you can also refer to the Install Harness GitOps Agent for steps on creating a new Harness GitOps Agent or on utilizing existing ArgoCD Agent.
-
Before proceeding, store the Agent Identifier value as an environment variable for use in the subsequent commands:
export AGENT_NAME=GITOPS_AGENT_IDENTIFIER
Note: Replace
GITOPS_AGENT_IDENTIFIER
with GitOps Agent Identifier. -
Create a GitOps Repository.
harness gitops-repository --file guestbook/harness-gitops/repository.yml apply --agent-identifier $AGENT_NAME
-
Create a GitOps Cluster.
harness gitops-cluster --file guestbook/harness-gitops/cluster.yml apply --agent-identifier $AGENT_NAME
-
Create a GitOps Application.
harness gitops-application --file guestbook/harness-gitops/application.yml apply --agent-identifier $AGENT_NAME
-
At last, it's time to synchronize the application with your Kubernetes setup.
-
Navigate to Harness UI > Default Project > GitOps > Applications, then click on gitops-application. Choose Sync, followed by Synchronize to kick off the application deployment.
-
Observe the Sync state as Harness synchronizes the workload under
Resource View
tab. -
After a successful execution, you can check the deployment in 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/kustomize-guestbook-ui 8080:80
-
- Congratulations! You successfully used
harness
CLI utility tool to create and execute a GitOps workflow.
-
Refer Install and Configure Harness CLI doc to setup and configure Harness CLI.
-
Fork the harnesscd-example-apps repository through the GitHub web interface.
-
Clone the Forked harnesscd-example-apps repo and change directory.
git clone https://github.com/GITHUB_ACCOUNTNAME/harnesscd-example-apps.git
cd harnesscd-example-appsnoteReplace
GITHUB_ACCOUNTNAME
with your GitHub Account name. -
Make sure you have a delegate configured and running smoothly. If not, you can also refer to the Install Harness Delegate on Kubernetes or Docker guide for steps on setting up the delegate using Helm, Terraform Helm Provider, or Kubernetes manifest.
-
Now, let's create all the resources that is required to execute a pipeline successfully. Let's start with creating a Harness Secret to store GitHub PAT.
- Obtain GitHub personal access token with repo permissions. For steps, go to the GitHub documentation on creating a personal access token.
- Create a Harness Secret to store GitHub PAT. This will be used in the next step to create GitHub connector.
harness secret apply --secret-name "harness_gitpat" --token GITHUB_PAT apply
Note: Replace
GITHUB_PAT
with GitHub PAT that you obtained in the previous step.
-
Create a GitHub connector.
harness connector --file guestbook/harnesscd-pipeline/github-connector.yml apply --git-user GITHUB_ACCOUNTNAME
Note: Replace
GITHUB_ACCOUNTNAME
with your GitHub Account Name. -
Create a Kubernetes connector.
harness connector --file guestbook/harnesscd-pipeline/kubernetes-connector.yml apply --delegate-name DELEGATE_NAME
Note: Replace
DELEGATE_NAME
with the Delegate name. -
Create a Environment.
harness environment --file guestbook/harnesscd-pipeline/environment.yml apply
-
Create a Infrastructure Definition.
harness infrastructure --file guestbook/harnesscd-pipeline/infrastructure-definition.yml apply
-
Create a Service.
harness service --file guestbook/harnesscd-pipeline/service.yml apply
-
Now, let's create a Pipeline of deployement type Canary with just a single command.
harness pipeline --file guestbook/harnesscd-pipeline/canary-pipeline.yml apply
-
Finally, it's time to execute the pipeline. Traverse through
Harness UI
>Default Project
>Pipelines
> Clickguestbook_canary_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 in 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/kustomize-guestbook-ui 8080:80
-
Congratulations! You successfully used
harness
CLI utility tool to create and execute a pipeline.