Deploy the plausible-analytics helm chart on AWS EKS
TypeScriptTo deploy the
plausible-analytics
Helm chart on an AWS EKS cluster using Pulumi, you'll need to follow the steps below:- Create an EKS Cluster: We'll need to set up an Amazon EKS cluster, which will serve as the environment on which
plausible-analytics
will be deployed. - Create an IAM Role: EKS will need an IAM role that provides the necessary permissions to the EKS service to manage resources on your behalf.
- Deploy the Helm Chart: Once the cluster is set up, and you have the necessary IAM permissions, we can proceed to deploy the
plausible-analytics
Helm chart on it.
Below is a Pulumi TypeScript program that demonstrates these steps. I'm going to use the high-level
@pulumi/eks
package that simplifies the creation of an EKS cluster.First, make sure you have the Pulumi CLI installed and AWS CLI configured with the necessary access credentials. You would also need to have Node.js installed to run the TypeScript program.
Here's how you set up the EKS cluster using Pulumi:
import * as pulumi from '@pulumi/pulumi'; import * as aws from '@pulumi/aws'; import * as eks from '@pulumi/eks'; import * as k8s from '@pulumi/kubernetes'; // Step 1: Create an EKS cluster const vpc = new aws.ec2.Vpc("vpc", { cidrBlock: "10.100.0.0/16", }); const subnet = new aws.ec2.Subnet("subnet", { vpcId: vpc.id, cidrBlock: "10.100.1.0/24", availabilityZone: "us-west-2a", }); const role = new aws.iam.Role("eksRole", { assumeRolePolicy: aws.iam.assumeRolePolicyForPrincipal({ Service: "eks.amazonaws.com" }), }); const policyAttachment = new aws.iam.RolePolicyAttachment("eksPolicyAttachment", { policyArn: aws.iam.ManagedPolicies.AmazonEKSClusterPolicy, role: role, }); const clusterSecurityGroup = new aws.ec2.SecurityGroup("clusterSecurityGroup", { vpcId: vpc.id, egress: [{ protocol: "-1", fromPort: 0, toPort: 0, cidrBlocks: ["0.0.0.0/0"] }], }); const eksCluster = new eks.Cluster("eksCluster", { vpcId: vpc.id, subnetIds: [subnet.id], instanceType: "t2.medium", desiredCapacity: 2, minSize: 1, maxSize: 3, storageClasses: "gp2", deployDashboard: false, roleMappings: [{ groups: ["system:masters"], roleArn: role.arn.apply(arn => arn), username: "admin", }], vpcCniOptions: { warmIpTarget: 4, }, }); // Step 2: Deploy the `plausible-analytics` Helm chart const helmChart = new k8s.helm.v3.Chart("plausible-analytics", { chart: "plausible", version: "1.2.3", // specify the version you wish to deploy namespace: "default", fetchOpts: { repo: "https://helm.plausible.io", }, }, { provider: eksCluster.provider }); // Export the cluster's kubeconfig. export const kubeconfig = eksCluster.kubeconfig;
In the above program:
- We create an AWS VPC and subnet to host the EKS cluster.
- We set up an IAM Role for our EKS cluster that allows the cluster to make calls to AWS services on your behalf.
- We create the EKS cluster using the
eks.Cluster
class, including setting up our node group with a desired instance type and scaling parameters. - We deploy the
plausible-analytics
application using aChart
resource from the@pulumi/kubernetes
package.
To run this Pulumi program:
- Place this code in a file named
index.ts
. - Run
pulumi up
in the same directory as yourindex.ts
file. This will provision the resources as per the code. - Once the deployment is successful, you can use the exported
kubeconfig
to manage the Kubernetes cluster and the deployedplausible-analytics
chart.
Remember to install the required node modules before running
pulumi up
by executing:npm install @pulumi/pulumi @pulumi/aws @pulumi/eks @pulumi/kubernetes
Keep in mind that EKS clusters can incur costs in your AWS account, and the
plausible-analytics
Helm chart may have its own set of requirements. Make sure to check the Helm chart's documentation for any prerequisites or configurations needed.- Create an EKS Cluster: We'll need to set up an Amazon EKS cluster, which will serve as the environment on which