Deploy the fastapi-app helm chart on AWS EKS
TypeScriptIn order to deploy the
fastapi-app
Helm chart on AWS EKS, we will follow these steps:- Create an EKS cluster using Pulumi's EKS package, which simplifies the process of creating an EKS cluster.
- Once the cluster is up, we will configure
kubectl
to connect to the new EKS cluster. - Finally, we will deploy the
fastapi-app
Helm chart to the EKS cluster.
Below is a detailed Pulumi program, written in TypeScript, which accomplishes the above steps.
Make sure you have the Helm CLI installed on your machine as this will be used by Pulumi to deploy the Helm chart.
First, we'll need to import the Pulumi libraries we require:
@pulumi/pulumi
for general Pulumi functions.@pulumi/aws
to work with AWS resources.@pulumi/eks
which provides a higher-level abstraction to work with EKS.@pulumi/kubernetes
to work with Kubernetes resources, such as Helm charts.
Here is the complete Pulumi program:
import * as pulumi from '@pulumi/pulumi'; import * as aws from '@pulumi/aws'; import * as eks from '@pulumi/eks'; import * as k8s from '@pulumi/kubernetes'; // Create an EKS cluster const cluster = new eks.Cluster("my-cluster", {}); // Export the clusters' kubeconfig. export const kubeconfig = cluster.kubeconfig; // Once the cluster is created, we can deploy a Helm chart to it. For example, if we're deploying // a 'fastapi-app' as a Helm chart, we'd assume this chart is available in a public or private chart repository. // The code below demonstrates how to deploy a Helm chart from a repository. // Create a Kubernetes provider instance that uses our EKS cluster from above. const provider = new k8s.Provider("k8s-provider", { kubeconfig: cluster.kubeconfig.apply(JSON.stringify), }); // Deploy the 'fastapi-app' Helm chart. const fastapiAppChart = new k8s.helm.v3.Chart("fastapi-app-chart", { chart: "fastapi-app", // If your Helm chart is in a repository, you must add the repository spec here: // repositoryOpts: { // repo: "http://charts.example.com/", // }, // If your Helm chart requires custom values, specify them inline here: // values: { // service: { // type: "LoadBalancer", // }, // }, }, { provider }); // If you need to export the LoadBalancer URL of your FastAPI app (assuming it's created // by your Helm chart), you'd use the following command. Note: This assumes your Service // is of type LoadBalancer and your chart deploys a Service named 'fastapi-service'. export const appUrl = fastapiAppChart.getResourceProperty("v1/Service", "fastapi-service", "status") .apply(status => status.loadBalancer.ingress[0].hostname || status.loadBalancer.ingress[0].ip);
Here's what the code is doing:
-
We create an EKS cluster using the
eks.Cluster
class. This will provision all the necessary infrastructure on AWS for an EKS cluster, including the control plane, default node group, and other necessary resources. You can further customize your EKS cluster in this step, such as specifying the desired Kubernetes version, node size, etc. -
Once the cluster is provisioned, we export the
kubeconfig
. This output can be used to interact with the Kubernetes cluster usingkubectl
. -
We define a new Kubernetes provider that points to our newly created EKS cluster. This provider will be used by Pulumi to deploy Kubernetes resources to the correct place.
-
We then use this provider to deploy a Helm chart named
fastapi-app
. You may need to provide the URL to the Helm repository where this chart is located using therepositoryOpts
parameter if it is not a publicly available Helm chart on a known Helm repo, like Bitnami or the official Helm stable charts. -
Finally, we export the URL of the application, which would be the hostname or IP provided by a LoadBalancer if your Helm chart deploys a Kubernetes Service of type LoadBalancer for the FastAPI app.
Please replace placeholder values like
chart
andrepo
with the actual values relevant for yourfastapi-app
Helm chart. Thevalues
property is a place where you can specify custom values for your Helm chart's deployment.To run this program, you will need to have Pulumi installed and configured for use with AWS. Then, you can simply run
pulumi up
in the same directory as the code above to create the EKS cluster and deploy the Helm chart.