Deploy the mysqld-exporter helm chart on AWS EKS
TypeScriptTo deploy the
mysqld-exporter
Helm chart on AWS EKS using Pulumi, you'll have to follow several steps:- Set up an AWS EKS cluster.
- Configure Pulumi to connect to the cluster.
- Deploy the
mysqld-exporter
Helm chart onto the EKS cluster.
We'll leverage the
@pulumi/eks
and@pulumi/kubernetes
packages to accomplish this. The@pulumi/eks
package simplifies the creation and configuration of an EKS cluster on AWS, and the@pulumi/kubernetes
package allows us to work with Kubernetes resources, including deploying Helm charts.Below is the program that deploys an EKS cluster and then the
mysqld-exporter
Helm chart:import * as eks from '@pulumi/eks'; import * as pulumi from '@pulumi/pulumi'; import * as k8s from '@pulumi/kubernetes'; // Create an EKS cluster. // [API Docs](https://www.pulumi.com/registry/packages/eks/api-docs/cluster/) const cluster = new eks.Cluster('my-cluster', { // Specify the desired settings for the cluster: instanceType: 't2.medium', desiredCapacity: 2, minSize: 1, maxSize: 2, storageClasses: 'gp2', deployDashboard: false, }); // Once the cluster is created, we can connect to it to deploy the mysqld-exporter Helm chart. const kubeconfig = cluster.kubeconfig.apply(JSON.stringify); // Create a Kubernetes provider instance that uses our EKS kubeconfig. const provider = new k8s.Provider('eks-k8s', { kubeconfig, }); // Deploy the mysqld-exporter Helm chart. // [API Docs](https://www.pulumi.com/registry/packages/kubernetes/api-docs/helm.sh/v3/chart/) const mysqldExporterChart = new k8s.helm.v3.Chart('mysqld-exporter', { chart: 'prometheus-mysqld-exporter', version: '1.0.0', // Specify the version of the chart you wish to deploy. fetchOpts: { repo: 'https://prometheus-community.github.io/helm-charts', }, }, { provider }); // Export the Kubeconfig and cluster name to enable interaction with the cluster via `kubectl` export const kubeconfigOutput = kubeconfig; export const clusterName = cluster.eksCluster.name;
Explanation:
-
We begin by creating a new EKS cluster named
my-cluster
with the desired settings, including the EC2 instance type and the number of desired instances. -
Once the EKS cluster is provisioned, we capture its kubeconfig which is required to interact with the Kubernetes API server.
-
A
Provider
resource is created that establishes the connection context to our EKS cluster, using the retrieved kubeconfig. -
We declare the
mysqld-exporter
Helm chart as aChart
resource, which will be installed into our EKS cluster. We provide the chart name, version, and the repository. -
The
provider
option passed to theChart
resource specifies which Kubernetes provider should be used to deploy the chart, which in this case is our EKS cluster.
In the code, replace
'1.0.0'
with the desired version of theprometheus-mysqld-exporter
Helm chart that you wish to deploy.To apply this program, save it to a file (e.g.,
index.ts
), ensure that you've configured your Pulumi account and AWS credentials, and then runpulumi up
. This command will provision the resources in AWS and deploy your Helm chart to the EKS cluster.