Deploy applications with the Helm provider
Helm is a package management tool for deploying applications to Kubernetes clusters. Helm charts help you define, install, and upgrade Kubernetes applications. Helm charts expose dozens of useful configurations and automatically set up complex resources.
The Terraform Helm provider allows you to deploy and manage your Kubernetes applications dynamically and securely. Using Terraform, you can provision clusters and deploy applications in the same apply operation. When you pass cluster authentication parameters to the Helm provider, Terraform's built-in dependency graph ensures proper ordering in resource creation.
In this tutorial, you will deploy the Nginx Helm chart to a Kubernetes cluster with Terraform. Nginx is a widely used webserver and it serves a static HTML file by default so you can verify the deployment.
Prerequisites
To run this tutorial, you will need:
- Terraform installed locally
- A running Kubernetes cluster. Follow the quick-start below, or for more in-depth instructions follow the Provision an EKS Cluster tutorial and do not destroy your cluster.
Create your EKS cluster
Create a new directory for your project.
Change into your project directory.
Clone the EKS cluster tutorial repo.
Change into the repository directory.
In your editor, open terraform.tf
and comment out the cloud block.
Run terraform init
.
Apply the EKS cluster configuration. Respond yes
at the prompt to confirm the operation.
It may take up to 10 minutes to deploy your EKS cluster.
Clone the example repository
After deploying your EKS cluster, change into your terraform_project
directory.
Clone the example repository for this tutorial.
Change into the repository directory.
This configuration uses data from the state file for your EKS cluster. Confirm the state file's path in your kubernetes.tf
file. If you deployed the EKS cluster in the quickstart above your state data source path is "../learn-terraform-provision-eks-cluster/terraform.tfstate"
.
The path
may be different on your machine, so modify the path to the state file if necessary.
Tip
 We recommend using provider-specific data sources when convenient. terraform_remote_state
 is more flexible, but requires access to the whole Terraform state.
Review the Helm configuration
In your editor, open learn-terraform-helm/helm_release.tf
.
The helm
provider block establishes your identity to your Kubernetes cluster. The host
and the cluster_ca_certificate
use your aws_eks_cluster
state data source to construct a method for logging in to your cluster. The exec
argument gets a short-lived token to authenticate to your EKS cluster.
Now, review the helm_release
resource block.
The helm_release
resource deploys the nginx
Helm chart from the Bitnami chart repository to your Kubernetes cluster. The values
parameter overrides the chart's default values. The file
function merges custom values from the nginx-values.yaml
file with the chart's default values.
Next, open the nginx-values.yaml
file.
The configuration uses the custom values in this file to override the chart's default values during deployment. You will modify these values later in this tutorial.
For more information about Helm values files, visit the Helm documentation.
Review the Helm chart
Helm charts are composed of two primary files: a Chart.yaml
file and a values file.
The Chart.yaml
file includes core information about the application you are deploying. The required values are the chart API version, the chart's name, and the chart's SemVer 2 version. For more information on chart configuration files, visit the Helm chart yaml
file documentation.
Deploy Nginx
Now initialize your configuration that deploys the helm chart.
Run terraform apply
. Respond yes
at the prompt to confirm the operation.
Verify Nginx
To verify that your Nginx deployment is working, visit the URL from the nginx_endpoint
output. It may take up to five minutes for Nginx to become available.
Modify Nginx
Now open learn-terraform-helm/nginx-values.yaml
.
Add the following to the bottom of the file, and save the file.
This serverBlock
custom value configures Nginx to return a custom HTTP response.
Now, redeploy nginx
with the updated values. Respond yes
at the prompt to confirm the operation.
Finally, verify the change.
Clean up your infrastructure
Destroy the infrastructure you created in this tutorial. Respond yes
at the prompt to confirm the operation.
Change into your EKS cluster configuration directory.
Destroy your EKS cluster. Respond yes
at the prompt to confirm the operation.
Next steps:
In this tutorial, you used Terraform to deploy Nginx to your EKS cluster with a Helm chart.
To learn more about Kubernetes and Helm, refer to the following resources:
- Deploy Consul with Helm tutorial
- Manage Kubernetes Resources via Terraform
- Review the
templatefile()
function to create templatized Helm values files