Deploy the sns-connector helm chart on AWS EKS
TypeScriptTo deploy the
sns-connector
Helm chart on AWS Elastic Kubernetes Service (EKS), you'll need to have an EKS cluster running and configured to work with the Helm package manager. Pulumi provides libraries that can help you accomplish this by creating the necessary resources and deploying the Helm chart.The following Pulumi program will:
- Create an EKS Cluster using the
eks
package since this is a high-level component that simplifies setting up an EKS cluster. - Setup an IAM role for the EKS cluster that allows it to manage resources (using
aws-iam
). - Deploy the
sns-connector
Helm chart into the EKS cluster using thekubernetes
provider which communicates with the cluster's Kubernetes API server.
Here's how you can do it in TypeScript:
import * as aws from "@pulumi/aws"; import * as awsx from "@pulumi/awsx"; import * as eks from "@pulumi/eks"; import * as k8s from "@pulumi/kubernetes"; import * as pulumi from "@pulumi/pulumi"; // Step 1: Create an EKS Cluster // The managed node group requires specifying an IAM role for the EC2 instances const eksRole = new aws.iam.Role("eksRole", { assumeRolePolicy: aws.iam.assumeRolePolicyForPrincipal({ Service: "eks.amazonaws.com", }), }); const eksRolePolicyAttachment = new aws.iam.RolePolicyAttachment("eksRolePolicyAttachment", { role: eksRole.name, policyArn: aws.iam.ManagedPolicy.AmazonEKSClusterPolicy, }); const eksNodegroupRole = new aws.iam.Role("eksNodegroupRole", { assumeRolePolicy: aws.iam.assumeRolePolicyForPrincipal({ Service: "ec2.amazonaws.com", }), }); const eksNodegroupRolePolicyAttachment = new aws.iam.RolePolicyAttachment("eksNodegroupRolePolicyAttachment", { role: eksNodegroupRole.name, policyArn: aws.iam.ManagedPolicy.AmazonEKSWorkerNodePolicy, }); const eksNodegroupRolePolicyAttachment2 = new aws.iam.RolePolicyAttachment("eksNodegroupRolePolicyAttachment2", { role: eksNodegroupRole.name, policyArn: aws.iam.ManagedPolicy.AmazonEKS_CNI_Policy, }); const eksNodegroupRolePolicyAttachment3 = new aws.iam.RolePolicyAttachment("eksNodegroupRolePolicyAttachment3", { role: eksNodegroupRole.name, policyArn: aws.iam.ManagedPolicy.AmazonEC2ContainerRegistryReadOnly, }); // Create the EKS cluster and a default node group const cluster = new eks.Cluster("my-cluster", { roleArn: eksRole.arn, tags: { Name: "my-cluster", }, vpcId: awsx.ec2.Vpc.getDefault().id, subnetIds: awsx.ec2.Vpc.getDefault().publicSubnetIds, instanceType: "t2.medium", desiredCapacity: 2, minSize: 1, maxSize: 2, nodeRole: eksNodegroupRole, }); // Export the clusters' kubeconfig. export const kubeconfig = cluster.kubeconfig; // Step 2: Deploy Helm chart into EKS cluster. const helmRelease = new k8s.helm.v3.Release("sns-connector", { chart: "sns-connector", version: "1.0.0", // Replace with actual chart version namespace: "default", // If chart values are required they should be specified in `values.yaml` file. // Alternatively, you can provide a values object directly, as shown below. values: { /* Replace with actual values, e.g.: serviceAccount: { create: true, name: "sns-connector-sa", }, */ }, }, { provider: cluster.provider }); // Export the Helm release status export const helmStatus = helmRelease.status;
This program creates an EKS cluster and deploys the
sns-connector
Helm chart. Before running this code, you should have Pulumi installed and configured for AWS access. Also, you would need to install the necessary Pulumi packages.The chart name
sns-connector
and version1.0.0
are placeholders and should be replaced with the actual name of the chart and its version you intend to use. If the Helm chart requires custom values, you would need to set them under thevalues: {}
block in thehelmRelease
resource as per the chart's requirements.To run this program, save it in a file (e.g.,
index.ts
), ensure you're logged in to Pulumi, and have AWS access configured, then perform the following steps in your terminal:- Run
pulumi stack init <stack-name>
to create a new stack. - Run
pulumi up
to preview and deploy the changes. - If everything looks good in the preview, select
yes
to proceed with the deployment.
After the deployment, you'll have an EKS cluster running the
sns-connector
Helm chart. The program exports thekubeconfig
needed to interact with your cluster usingkubectl
and the deployment status of your Helm release.- Create an EKS Cluster using the