Enabling On-Demand Runners Using Kubernetes
Warning
This content is part of the legacy version of Waypoint that is no longer actively maintained. For additional information on the new vision of Waypoint, check out this blog post and the HCP Waypoint documentation.
A Waypoint runner executes each build, deployment, and release operation that Waypoint performs. The runner accepts jobs from the server, executes the necessary operations, and then either waits for additional jobs to be queued or exits. Runners that are long-lived and execute many jobs over time are known as static runners, while those that are created per-job and exit upon completion are known as on-demand runners (ODRs).
On-demand runners are ephemeral, short-lived container instances that exist only for as long as they are needed to complete the operations assigned to them. A few key benefits of on-demand runners over static runners are that they can perform container builds without privileged access, offer more isolation between operations, and allow Waypoint to scale further dynamically.
In this tutorial, you will install static runners into Kubernetes and use runner profiles that allow those static runners to create on-demand runners for executing Waypoint operations in response to changes you will make to a remote Git repository.
Scenario and runner overview
There are two Kubernetes clusters that you will create as part of this tutorial: the first will contain the Waypoint server and be a default app deployment environment while the second will be an environment specific to a team and their desire to restrict Waypoint operations to their own isolated cluster.
A static runner in each cluster that is registered with the Waypoint server is responsible for managing the on-demand runners in their respective cluster.
Tip
The following commands are examples - you do not need to run any of them.
The runner configuration that is part of the installation process includes key-value labels that describe or identify the runner. These labels are user-generated strings and can be attributes such as cluster location, environment level, or other identifying values.
A runner profile uses these labels to target specific runners during the execution of the Waypoint operations through the -target-runner-label
flag.
Once the runners are set up, you can target a runner by adding the runner
block with a profile name to the waypoint.hcl
file.
The on-demand runners in this tutorial use the Kubernetes task plugin. ODR functionality is plugin-based so additional cloud providers or environment plugins can be created by users in the event that a plugin is not already available. Waypoint currently supports several plugins including Kubernetes, HashiCorp Nomad, AWS ECS, and Docker by default.
Prerequisites
For this tutorial, you will need:
- Waypoint v0.10.2 or later installed locally
- Terraform v1.0.7 or later installed locally
- An account on a hosted Git provider site (GitHub, GitLab, Bitbucket, etc.) and Git installed locally
- An AWS account with credentials set as local environment variables and the AWS CLI installed
- A DockerHub account
- Kubectl installed locally
- (Optional) Helm installed locally
Note
This tutorial creates AWS resources that may not qualify as part of the AWS free tier. Be sure to follow the Cleanup process at the end so you don't incur any additional unnecessary charges.
Set up the container registry
This tutorial uses DockerHub as the image registry but you can use other registry services. The visibility of the DockerHub repository is public so that the Waypoint runners in Kubernetes can pull these images without additional authentication.
Create the access token
Create a new DockerHub access token by navigating to the security settings page and clicking on the blue New Access Token button. Type waypoint
in the Access Token Description field, select Read, Write, Delete from the Access permissions dropdown, and click Generate.
Copy the token value and export it as a local environment variable.
Click on the Copy and Close button to close the dialog box.
Export your DockerHub username as a local environment variable.
Clone the example repository
The example repository includes the Terraform configuration to create the two Kubernetes clusters and the supporting infrastructure including networking and IAM resources. It also contains an example NodeJS application from the Waypoint examples repository located in the app
directory.
Clone the example repository.
Change into the learn-waypoint-odr directory.
Create infrastructure
First, initialize your Terraform configuration.
Apply the configuration to create the Kubernetes clusters and supporting infrastructure. This process will take a few minutes to complete.
Tip
Resources will be created in the us-east-2
region by default. If you would like to create them in another region, update the aws_region
and availability_zones
variables in the variables.tf
file.
Update your local kubeconfig file with the primary EKS cluster information.
Then, update your local kubeconfig file with the secondary EKS cluster information.
Install Waypoint
Install server in primary cluster
Install the Waypoint server and runner into the primary cluster.
Authenticate to the Waypoint UI.
Note
Your browser may warn you that the site is not secure, this is because Waypoint uses a self-signed certificate by default but TLS is still enabled.
Install runner in primary cluster
Runners can be installed with either the waypoint runner install
CLI command or Helm.
With the waypoint runner install
method, Waypoint automatically adopts the runner and creates a runner profile for it. You can skip this automatic adoption and profile creation by including the -skip-adopt
flag but you will then need to manually adopt the runner and create a profile.
The Helm install requires additional configuration steps to adopt the runner, set up the runner profile, and modify the runner service account in Kubernetes.
Tip
We recommend installing runners with waypoint runner install
as it simplifies the process and does not require the Helm CLI.
Get the hostname of the primary cluster from the kubectl
output and save it as an environment variable.
Install the runner by providing the server cookie and hostname of the primary cluster. Note the runner label being added with the -label
flag as well as the -k8s-context
flag specifying the context for the primary cluster.
Verify that the runner exists.
Tip
The runner with the static
ID is automatically installed during the Waypoint server installation process.
Verify that the runner profile exists for the new runner.
Install runner in secondary cluster
The installation process for the runner in the secondary cluster is the same as the one for the runner in the primary cluster.
Note
Make sure you have followed the steps from the Install runner in primary cluster section above before continuing with the secondary cluster runner installation.
Install the runner.
Verify that the runner exists.
Verify that the runner profile exists for the new runner.
Prepare the project repository
Create a new, empty public Git repository on a hosted Git platform like GitHub, GitLab, or Bitbucket. For this tutorial, the repository is public but Waypoint does support basic password and SSH authentication if you want to use a private repository.
Create an environment variable named MY_REPO_URL
and set the value to the URL of your public git repository.
Change to the app
directory of the example repository.
Initialize a new git project.
Create and switch to a new branch named main
.
Add your new public Git repository as the remote repository URL.
Add the runner
block to the waypoint.hcl
file inside the app
block and save the file.
1 2 3 4 5 6 7 8 9 10111213
Add and commit all of the files in the directory.
Finally, push the contents to the main branch of your repository.
Note
If your repository has a README or other template file, you may encounter an error that instructs you to fetch updates first. Run a git fetch
to retrieve and merge the files locally or add the --force
flag to the git push
command if you want to overwrite any remote files.
Create project with runner profile
Create the Waypoint project.
Add configurations for image name, registry username, and registry password at the Waypoint project level. Note that the -runner
flag is added to make these available as environment variables to on-demand runners used by the project.
Tip
These waypoint config set
commands will not print any output when they complete.
Set the image name.
Then, set your registry username.
Finally, set your registry password.
Warning
These values are stored in the Waypoint server. Setting the registry configurations here are done so for development and illustration purposes.
View the configurations for the runners used by the project.
Modify the Waypoint project to add a reference to the Git repository and enable GitOps.
Waypoint will begin the initial build, deploy, and release operations for the project and then each time a change to the repository is made. These initial operations will happen on the primary cluster as the waypoint.hcl
file contains the kubernetes-PRIMARY-CLUSTER-RUNNER
profile.
Verify that the application is running on the correct cluster by listing the pods in the primary cluster. The application pod will take some time to deploy and change to the running
state. Note the pod with the application name and v1
- in this case nodejs-example-v1-94f77f4dd-w4pf7
.
Modify repository code
Open the views/pages/index.ejs
file, add a new H2
heading with text, and save the file.
Open the waypoint.hcl
file, update the runner profile to use the one for the secondary cluster runner, and save the file.
Add and commit the updated files.
Then, push the contents to the main branch of your public repository.
Waypoint will detect the changes made to the repository and run the build, deploy, and release operations. This may take some time. Once complete, view the updated app from the deployments page in the Waypoint UI by clicking on the gray button with the waypoint.run
generated URL. You can also use the Kubernetes load balancer release URL by clicking the blue button in the top right of the page.
Verify that the application is running on the correct cluster by listing the pods in the secondary cluster. Note the pod with the application name and v2
- in this case nodejs-example-v2-ffc77446d-t69sv
.
Trigger the remote runner locally
You can trigger projects with a remote Git configuration from your local machine with the Waypoint CLI by adding -local=false
to the waypoint up
command.
Warning
When running waypoint up
locally, the CLI will read the runner profile from the local waypoint.hcl
file, not the one in the remote Git repository. However if you want to change any of your app configurations, they must be committed into the remote Git repository, as Waypoint will read app configurations from the remote waypoint.hcl
file.
Update the runner profile in waypoint.hcl
to use the runner in the primary cluster and save the file.
Then run waypoint up
with the -local=false
flag.
Tip
Waypoint reads the project name from the waypoint.hcl
file present in the current directory if it is not explicitly set it with the -project
global flag.
Verify that v3
of the application is running in the primary cluster.
Cleanup
There are two ways of cleaning up once you are finished with Waypoint. The first involves destroying the Waypoint project resources, then the runners and runner profiles, and finally the underlying infrastructure. The second involves using Terraform to destroy the infrastructure and, at the same time, all of the Waypoint project resources.
We recommend the first method as it helps you become more familiar with the resources involved in using Waypoint.
Delete the project and all of the resources associated with it. This includes deployents and releases.
Uninstall the runners.
First, the runner in the primary cluster.
Then, the runner in the secondary cluster.
Move back up to the root directory of the repository.
Clean up your provisioned infrastructure. Respond yes
to the prompt to confirm the operation.
Note
The load balancers created by Kubernetes as part of the release operation are not managed by Terraform but there is a cleanup module that takes care of deleting them. In the event that it doesn’t work the first time, re-run terraform destroy
. If that still does not work, you may need to navigate to the load balancers section of the AWS console and delete them manually.
Next Steps
In this tutorial, you installed static runners into separate Kubernetes clusters, created and associated runner profiles to them, and then used those profiles to get Waypoint to dynamically create and use on-demand runners when you made changes to your waypoint.hcl
file from your remote Git repository.
For more information, check out the following resources.
- Read more about on-demand runners
- Learn how to use HCP Waypoint with your own infrastructure
- Learn how to deploy a Helm-based application with GitOps
- Learn how to extend Waypoint by creating a plugin