Deploy a Helm-based application automatically with GitOps
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.
Kubernetes is a widely adopted platform for running containerized workloads which has become a standard in the industry. Operations teams that maintain a cluster of their own know that the orchestration functionality that Kubernetes provides means that once applications are deployed, they are reliable, highly available, and can be updated or rolled back without downtime.
However, deploying applications to the cluster can be a difficult process, often involving the authoring of many manifest files depending on the complexity of the application. Helm is a tool that helps teams manage these manifest files with either pre-made templates for deploying common applications or the ability to craft their own custom template.
Users then deploy these templates with Helm from their local machines or a centralized continuous integration and deployment server. The local deployment scenario involves several manual steps while the CI server scenario is automatic but involves setting up and configuring the CI tool before the Helm application can be deployed at all.
Waypoint helps simplify the deployment process with its Helm plugin and does so automatically with its Git integration and GitOps. Waypoint polls the Git repository for changes and performs the steps present in the waypoint.hcl
file, including build, deploy, and release processes.
In this tutorial, you will install Waypoint into an existing Kubernetes cluster, integrate a Git repository containing a Helm-based application with a Waypoint project, and have Waypoint deploy that application to the Kubernetes cluster with the Waypoint Helm plugin.
Prerequisites
For this tutorial, you will need:
- Waypoint 0.6 or later installed locally
- An account on a hosted Git provider site (GitHub, GitLab, Bitbucket, etc.) and Git installed locally
- A running Kubernetes cluster (cloud-based or local)
- Learn guides for provisioning a cluster exist for AWS, Azure, and Google Cloud
- Local cluster running with minikube, Kubernetes for Docker Desktop, kind, etc.
- Kubectl installed locally and a kubeconfig file with access configured for the cluster above
Install the Waypoint Server to Kubernetes
The Waypoint server is officially supported to run on Kubernetes, Nomad, Amazon ECS, and Docker. The waypoint install
command for Kubernetes creates the necessary Waypoint server resources, including a Service, Statefulset, Deployment, and Replicaset. The Waypoint server and its runner are set up by default to run as two separate pods. To learn more about runners visit the Waypoint runners documentation page.
First, make sure that kubectl
is configured to interact with your Kubernetes cluster by viewing the cluster information, checking the kubeconfig, and getting the nodes.
Then, install the Waypoint server.
Tip
Waypoint can also be installed with the official Waypoint Helm chart as outlined here but this tutorial uses the waypoint server install
command as it doesn't require Helm to be installed locally.
Waypoint creates a LoadBalancer resource as part of the Kubernetes install process. In order to complete this process in the minikube cluster, you must have a tunnel running in the background. This exposes the cluster and makes it available to any other services running on your local machine.
In a separate terminal session, start the minikube tunnel and enter your computer’s password when prompted. Do not close this session.
Navigate back to the original terminal session and run the install command. The -k8s-advertise-internal
flag is required as there is no external address associated with the cluster. The -accept-tos
flag is to accept the Terms of Service and Privacy Policy of the Waypoint URL Service.
Authenticate with the Waypoint UI. This will open the web UI in your browser.
Your browser will prompt you that the connection is not private since Waypoint is using a self-signed certificate. Click through the warning page to proceed to the UI.
Clone the Example Repository
The example repository contains a Helm-based version of the HashiCups application. It includes Helm charts, values files, and templates for each of the microservices that make up HashiCups. It also contains waypoint.hcl
, the Waypoint project configuration file and the runner-configs.yaml
file, a Kubernetes manifest that adds additional permissions to the waypoint-runner service account.
Clone the example repository and change into the learn-waypoint-helm-deploy directory.
Check out the v0.1
tag of the repository as a local branch named hashicups
.
Review Repository Contents
There are five top-level directories, one for each microservice, that contain the Helm configuration files for that microservice. Navigate to the frontend/helm
directory.
This directory follows the structure defined for a Helm chart and contains a Chart.yaml
file with metadata about the chart, a values.yaml
file with application image information, and a template
directory with the Kubernetes manifest for the frontend service.
The values.yaml
file refers to a pre-built HashiCups frontend image. Each of the services defined in the other directories follow the same convention.
Navigate to the templates
directory.
The frontend.yaml
file here contains the resource definitions for deploying the frontend service to Kubernetes: a Service, a ConfigMap with an Nginx configuration, and a Deployment that uses the Nginx ConfigMap.
Note that the ConfigMap uses the Kubernetes DNS name for the public-api
service that will be deployed.
1 2 3 4 5 6 7 8 9 10111213141516171819202122
Navigate back to the root of the repository directory.
The runner-configs.yaml
file is a Kubernetes manifest file that adds a ClusterRole with permissions to create namespaces and a ClusterRoleBinding to connect it to the waypoint-runner service account.
Finally, the waypoint_example_hcl
file shows an example configuration of HashiCups as a Waypoint project with the public-api
service defined as a Waypoint application. The application is configured to use the Helm deployment plugin and the contents of the public-api/helm
directory.
Note that the build
block is using the docker-pull
plugin which doesn’t build a Docker image but rather pulls a pre-built one. Waypoint can build a Docker image before continuing with the deploy and release phases with the docker
build plugin but this tutorial focuses on using pre-built images. More information about the build phase can be found here.
By default, Waypoint enables the public URL service functionality but setting the auto_hostname
attribute to false in the url
block disables it. The public-api
below is accessed from the frontend service so a public URL is not necessary.
Helm specific deployment values can also be defined with the set
block in the Helm plugin configuration.
1 2 3 4 5 6 7 8 9 10111213141516171819202122232425262728293031323334353637383940
Setup a New Git Repository for Waypoint
Create a new empty public Git repository on a hosted Git platform like GitHub, GitLab, or Bitbucket. For this tutorial, a public repository is used 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.
Warning
If you are using a private repository, be sure to use the SSH repository URL instead of the http(s) one.
Then, navigate back to the example repository directory in your terminal and verify that the remote URL is set to the original example repository.
Set your new public Git repository as the remote repository.
Create a waypoint.hcl
file, add the configuration below to it, and save the file.
Add and commit the updated Waypoint file.
Finally, push the contents to the hashicups
branch of your public repository.
Warning
If you created a new repository with a README or other template files, 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.
Add a Waypoint Project and Configure Git Integration
A Waypoint project can be configured with Git repository information through the CLI or web UI. Once configured, Waypoint polls the repository and automatically executes the steps defined in the waypoint.hcl
file when changes are made to the repository, similar to running waypoint up
.
Before configuring the Git project integration, apply the runner-config.yaml
manifest file from your terminal session.
Next, configure the project.
Note
The apply command below uses the MY_REPO_URL
environment variable from earlier so be sure to use the same shell or set the variable again.
Warning
If you are using a private repository, you need to add the -git-auth-type
flag and the associated flags depending on whether you're using basic or ssh authentication: -git-username
and -git-password
for basic auth or -git-private-key-path
and optionally -git-private-key-password
for ssh auth. See the waypoint project apply
docs page for more information.
Waypoint will execute the build, deploy, and release steps configured in the waypoint.hcl
file after this initial project setup is complete. It will then periodically poll the repository for changes going forward and perform the same execution process when changes are detected.
Note
If a project with the name used in the apply
command doesn’t exist, a new one will be created and configured by Waypoint. If one does exist, Waypoint will update the project’s configurations.
View the status of that initial execution. The context shown in the output may be different depending on where your cluster and Waypoint server are running.
Tip
The -project
and -app
flags can be passed to waypoint status
if you want to see the status of a specific project and/or app within it.
Finally, view the new project’s configuration.
Modify the Repository and Redeploy
Changes pushed to the configured repository will be picked up by the Waypoint server when it polls next. The polling interval is set with the -poll-interval
configuration flag. If this is not set explicitly in a project apply
command, it will default to 30 seconds.
Update the frontend image version to v0.0.7
in waypoint.hcl
.
123456789
Then, update the Helm configuration to the same version in frontend/helm/values.yaml
.
12345
Note
Updating the waypoint.hcl
file with the new version isn’t strictly necessary as the build phase for this project isn’t building the image but instead pulling from a public repository. However, it’s a good idea to keep the waypoint.hcl
file consistent with any changes made to the Helm deployment configurations.
Add and commit these changes to your repository.
Then, push the changes. Waypoint will start the execution process soon after.
Verify the Project and Application
Check the status of the project to see that the changes have been applied and the DEPLOYMENT CHECKED
field of the output has been updated with a more recent timestamp.
Verify that the HashiCups app was deployed successfully.
In a separate shell tab, create a port forwarding connection for the frontend service.
Navigate to the HashiCups web UI in your browser at http://localhost:8080
.
Click on the blue Buy button to see the payment page.
Cleanup
Destroy the HashiCups project in Waypoint to remove the Kubernetes resources created with the Helm deployment.
Note
The Waypoint UI will still display the applications on the hashicups project page even though all deployed resources have been destroyed. A feature request to address this has been created and can be tracked here.
Then, uninstall the running Waypoint server. The CLI will read the current context and determine that the server is running in Kubernetes.
Warning
Remember to destroy your cloud-based Kubernetes cluster if you’ve created one for this tutorial so you don’t incur additional costs.
Next Steps
In this tutorial, you installed the Waypoint server to an existing Kubernetes cluster, configured a Waypoint project to integrate with a Git repository and automatically deploy changes, and used the Helm deployment plugin to deploy a Helm-based app to your existing Kubernetes cluster.
Using the Helm plugin allows you to simplify your Kubernetes application deployment process and continue to leverage your existing Kubernetes deployment templates. Waypoint also supports integration with Git projects. This Git integration decreases the time it takes to deploy applications by leveraging automated GitOps workflows.
For more information, check out the following resources.
- Learn more about the Helm deployment plugin
- Read more about the Git integration on the blog and the documentation page
- Read more about the Kubernetes-related features in Waypoint 0.6