Services

Updated 1 week ago by Michael Cretzman

Services represent your microservices/apps. You define where the artifacts for those services come from, and you define the container specs, configuration variables, and files for those services.

This is a general overview of a Harness Service. For detailed deployment information for each type of Service, see Deployments Overview and select your deployment type.

Intended Audience

  • DevOps

Before You Begin

Add a Service

To add a service, do the following:

  1. Click Setup, and then click the name of your application. The application entities appear.
  2. Click Services, and then click Add Service. The Service dialog appears.
  3. Select a Deployment Type. Each deployment type will set up a Service for its deployment platform. For example, selecting Kubernetes creates a Service with default Kubernetes manifest files.
  4. Click SUBMIT. The Service Overview appears.
    In this new Service you will set up artifacts, container specs, and configuration files and variables.

Different Service Types

There are multiple Service types used in Harness, listed in the Deployment Type field, such as Kubernetes and Helm.

These Service types are discussed in detail in the deployment guides for those platforms. For more information, see Deployments Overview.

Artifact Sources

Different Service types support different artifact sources, such as Docker or Amazon AMI. For details on different service types and artifact sources, see Service Types and Artifact Sources.

Manually Select an Artifact

You can have Harness pull a list of builds and versions from an Artifact Source. Click Artifact History, and then Manually pull artifact. The Manually Select An Artifact dialog appears.

Select the artifact source in Artifact Stream, and then the artifact build in Artifact.

Container Specs and Manifests

You can use container specifications and manifests to configure a Service. For information on the specs and manifests available for the different Service types, see Deployments Overview.

Scripts

For shell script-based Services, the Deployment Specifications section has options and templates for you to add Bash and PowerShell scripts for use in the deployment of this Service.

Template Library

The Template Library has a wealth of scripts you can use to rapidly develop your script. For more information, see Use Templates.

  1. In the Script section of Deployment Specification, click Add Command. The Add Command dialog appears.
  2. Click From Template Library. The Template Library is displayed. Find the template you need.
  3. Click Link or click the drop-down menu and choose Copy. You can link to a templates or copy a template to your service. If you link to the template, when that version of the template is updated in the Template Library, your script is also updated. If you copy a template, there is no link to the Template Library. If you link to a template, you may only edit the template from the template dialog. You cannot edit the template in your service.
  4. Edit the script if needed and click SUBMIT. The script is added to your service.
    Every time you edit a template, you create a new version of it. To switch versions, click the three dots on the script title bar and choose Manage Versions.
  5. To edit the variables used in the script, click Variables. The Edit Command dialog opens. Edit the variables and click SUBMIT.

Create a New Command

  1. In the Script section of Deployment Specification, click Add Command. The Add Command dialog appears.
  2. Click Create New.
  3. In Name, enter a name for the new command that describes its function.
  4. From Command Type, select the function of the command, such as Start, Install, Disable, etc.
  5. Click Submit. The new command is added under Script.
  6. Mouseover the Add button to see the available commands.
  7. Click a command from the list. The dialog for the command appears. For example, here is the dialog for the Docker Start command.
    The dialog contains a default script relating to it type. The script is prefigured for variables for common application information.
  8. From Script Type, select BASH or POWERSHELL.
  9. Modify the script is needed and click SUBMIT. The command is added to the Script section:
  10. Click the command icon to see or modify the script.
  11. Mouseover the command icon to see a plus icon. Mouseover the icon to see the command list and select another command for your script.

Configuration Variables and Files

For information about how configuration variables and files are used in a Kubernetes deployment, see Kubernetes Deployments Overview. For information on using Harness variables and expressions, see Variables and Expressions in Harness.

You can add Service-level variables and files to use throughout your Service configuration settings.

Config Variables

To use Service-level variables, do the following:

  1. In Configuration, in Config Variables, click Add Variable. The Config Variable dialog appears.
  2. In Name, enter a name for your variable. This is the name you will use to reference your variable anywhere in your service.
  3. In Type, select Text or Encrypted Text.

    If you selected Text, enter a string in Value. When you reference this variable in the Service configuration, you use ${serviceVariable.var_name}.

    If you select Encrypted Text, the Value field becomes a drop-down and you can select any of the Encrypted Text you have configured in Secrets Management. For more information, see Secret Management. You can also click Add New Encrypted Text to create a new secret. When you reference this encrypted variable in the Service configuration, you use ${serviceVariable.var_name}.

    You can also use Harness variables in the Value field. To use a variable, enter $ and see the available variables.
    For example, to add workflow variables, enter ${workflow and the available workflow variables are displayed. For more information about variables, see Variables and Expressions in Harness.
  4. Click SUBMIT. The variable is added to Config Variables.
  5. To reference the variable is any text field in your service configuration, type $ and Harness will provide a drop down of all variables. Begin typing the name of your variable to find it and select it.

Config Files

Files added in the Config Files section are referenced using the configFile.getAsString("fileName") Harness functor:

  • ${configFile.getAsString("fileName")} - Unencrypted text file.
  • ${configFile.getAsBase64("fileName")} - Encrypted text file.

For example, let's add a Config Files file named config-file-example.txt.

You would reference this file like this:

${configFile.getAsString("config-file-example.txt")}  

Reference Service Variables and Secrets

Once you have created a Service variable, either text or a secret using one of the secrets in Secrets Management, you can use it in other Harness Application components such as Workflows by entering ${serviceVariable. and selecting the variables.

Override Values YAML

For information on Helm Values YAML, see Kubernetes Deployments Version 2 and Helm Deployments.


How did we do?