Deploy the variant-service-deployments helm chart on AWS EKS
TypeScriptTo deploy a Helm chart on an AWS Elastic Kubernetes Service (EKS) cluster using Pulumi, you'll need to follow these steps:
- Set up an EKS cluster.
- Configure Kubernetes provider to connect to the EKS cluster.
- Deploy the Helm chart to the EKS cluster.
Let's break down each of these steps with accompanying Pulumi code, using the TypeScript language.
Step 1: Setting up an EKS Cluster
We use the
eks.Cluster
resource from the@pulumi/eks
package, which simplifies creating and managing an EKS cluster.import * as eks from "@pulumi/eks"; // Create an EKS cluster. const cluster = new eks.Cluster("my-cluster", { desiredCapacity: 2, minSize: 1, maxSize: 3, storageClasses: "gp2", // Specify the storage class. deployDashboard: false, // EKS dashboard is optional. }); export const kubeconfig = cluster.kubeconfig;
In the example above, we're creating an EKS cluster with the desired capacity of worker nodes. The
storageClasses
option specifies the storage class for the cluster's volumes, anddeployDashboard
indicates we're not deploying the Kubernetes dashboard.Step 2: Configuring the Kubernetes Provider
The Kubernetes provider needs to be configured to connect to the EKS cluster. We use the kubeconfig output from the EKS cluster to achieve this.
import * as k8s from "@pulumi/kubernetes"; // Create a Kubernetes provider instance that uses our EKS cluster's kubeconfig. const k8sProvider = new k8s.Provider("k8s-provider", { kubeconfig: cluster.kubeconfig.apply(JSON.stringify), });
Here,
cluster.kubeconfig.apply(JSON.stringify)
is converting the kubeconfig output to a JSON string, which the Kubernetes provider can use.Step 3: Deploying the Helm Chart
With the Kubernetes provider configured, you can now deploy your Helm chart to the EKS cluster using the
helm.v3.Chart
resource from the@pulumi/kubernetes
package.import * as k8s from "@pulumi/kubernetes"; // Deploy a Helm chart. const helmChart = new k8s.helm.v3.Chart("variant-service", { chart: "variant-service-deployments", version: "1.0.0", // Specify the version of the chart. fetchOpts: { repo: "http://myhelmrepo.com", // Specify the Helm repository URL. }, }, { provider: k8sProvider });
In this example, we're deploying the
variant-service-deployments
Helm chart, which is presumed to be version1.0.0
and located in a custom Helm repository athttp://myhelmrepo.com
.Bringing it all together
Combining all the steps above, here is the entire Pulumi program for deploying a Helm chart to an EKS cluster:
import * as eks from "@pulumi/eks"; import * as k8s from "@pulumi/kubernetes"; // Step 1: Create an EKS cluster. const cluster = new eks.Cluster("my-cluster", { desiredCapacity: 2, minSize: 1, maxSize: 3, storageClasses: "gp2", deployDashboard: false, }); // Export the cluster's kubeconfig. export const kubeconfig = cluster.kubeconfig; // Step 2: Configure the Kubernetes provider using the generated kubeconfig. const k8sProvider = new k8s.Provider("k8s-provider", { kubeconfig: cluster.kubeconfig.apply(JSON.stringify), }); // Step 3: Deploy the Helm chart to the EKS cluster with the Kubernetes provider. const helmChart = new k8s.helm.v3.Chart("variant-service", { chart: "variant-service-deployments", version: "1.0.0", fetchOpts: { repo: "http://myhelmrepo.com", }, }, { provider: k8sProvider }); // Optionally, if you need to pass specific config values to your Helm chart you can do so as follows: // const helmChart = new k8s.helm.v3.Chart("variant-service", { // ... // values: { // serviceType: "LoadBalancer", // replicaCount: 3, // }, // }, { provider: k8sProvider });
Make sure you replace
"http://myhelmrepo.com"
with the actual URL of your Helm repository and adjust theversion
,chart
, andvalues
as needed for your specific Helm chart.To run this program, save it to a
index.ts
file, set up your Pulumi stack and AWS credentials, and then execute it usingpulumi up
. It will provision the necessary resources on AWS and deploy the Helm chart to your EKS cluster.