Deploy the python-fastapi-postgres helm chart on Linode Kubernetes Engine
TypeScriptDeploying a Helm chart to a Kubernetes cluster on Linode Kubernetes Engine (LKE) can be achieved using Pulumi's TypeScript SDK. In this case, you want to deploy a Helm chart for a
python-fastapi-postgres
application. The Helm chart encapsulates the deployment of both the FastAPI application and a PostgreSQL database.Here's a step-by-step guide followed by a Pulumi program written in TypeScript:
Step-by-Step Guide
-
Linode Kubernetes Cluster: First, you'll need a Kubernetes cluster running on Linode. Pulumi can provision an LKE cluster for you.
-
Helm Chart: Once you have the Kubernetes cluster, you'll use Pulumi's Kubernetes provider to deploy a Helm chart. You'll specify the chart for
python-fastapi-postgres
. This assumes there's an existing Helm chart available that you can use. If not, you'll need to create one or find a suitable alternative. -
Helm Release: Deploying the Helm chart creates what's known as a "Helm release." This is the actual running instance of the chart in your cluster.
-
Configuration: You'll need to provide any necessary configuration values required by the Helm chart, for instance, any environment variables or database credentials the FastAPI application expects.
Pulumi TypeScript Program
Below is a Pulumi program in TypeScript. The program assumes that you have a pre-existing Helm chart for your
python-fastapi-postgres
application. If you have your own Helm chart, replace thechart
andrepo
values with your chart's details.import * as linode from "@pulumi/linode"; import * as k8s from "@pulumi/kubernetes"; // Step 1: Create the Linode Kubernetes Engine Cluster const cluster = new linode.LkeCluster("my-cluster", { k8sVersion: "1.20", // specify your desired Kubernetes version label: "my-cluster", region: "us-central", // specify the Linode region tags: ["pulumi-deployed"], nodePools: [{ count: 2, // specify the number of nodes type: "g6-standard-2", // specify the type of node }], }); // Step 2: Use the Pulumi Kubernetes Provider to interact with the created Linode Kubernetes Cluster const k8sProvider = new k8s.Provider("my-k8s-provider", { kubeconfig: cluster.kubeconfigRaw, }); // Step 3: Deploy the Helm chart for the python-fastapi-postgres application const fastapiApp = new k8s.helm.v3.Chart("python-fastapi-postgres-chart", { chart: "python-fastapi-postgres", version: "1.0.0", // specify the version of the Helm chart namespace: "default", fetchOpts: { repo: "http://my-charts-repo.local", // URL of the Helm chart repository }, values: { // Provide any necessary values for your chart here. // This is an example and you'll likely need to adjust this based on your Helm chart's values postgresql: { postgresUser: "fastapi", postgresPassword: "changeit", // make sure to use a secure way of handling passwords postgresDatabase: "fastapi_db", }, }, }, { provider: k8sProvider }); // Export the public endpoint of the FastAPI application export const fastApiEndpoint = fastapiApp.getResourceProperty("v1/Service", "python-fastapi-postgres-chart", "status").apply(status => status.loadBalancer.ingress[0].ip);
Explanation
In the above program:
-
We import the
linode
andkubernetes
modules that allow us to interact with Linode resources and Kubernetes resources respectively. -
A cluster is created on Linode with the specified version and node specifications in the designated region.
-
A Kubernetes provider instance is set up to interact with the newly created Linode Kubernetes Cluster using the provided kubeconfig.
-
We deploy the Helm chart using
k8s.helm.v3.Chart
. It references the chart location withrepo
and any necessary configurations within thevalues
block. You'll need to modify therepo
URL andvalues
to fit your setup.
In this example, we create a
Service
resource that would expose the FastAPI application. The public IP endpoint is then exported, allowing you to access the FastAPI application from outside the cluster.Remember that this Helm chart and associated values are placeholders; make sure to replace them with actual details specific to your chart and application requirements. The
postgresPassword
should be managed as a secret, not in plaintext, for production scenarios. Pulumi supports various ways of managing secrets securely.After writing the program:
- Save this TypeScript code in a file (e.g.,
index.ts
). - Run the program with Pulumi by executing
pulumi up
, which will create the resources specified. - After the deployment is complete, the output will display the
fastApiEndpoint
. This is the public IP address which you can use to access the FastAPI application.
-