Deploy the fastapi-app helm chart on Oracle Kubernetes Engine (OKE)
TypeScriptTo deploy the
fastapi-app
Helm chart on Oracle Kubernetes Engine (OKE), we will follow these steps:- We will set up the necessary prerequisites, such as installing Pulumi and configuring access to Oracle Cloud.
- We will write a Pulumi program in TypeScript to define our cloud resources.
- The Pulumi program will create a Kubernetes cluster using OKE (Oracle Kubernetes Engine).
- We then deploy the
fastapi-app
Helm chart on the OKE cluster.
Here is how we accomplish this:
Prerequisites Installation and Setup
Make sure you have Pulumi installed and configured for use with your Oracle Cloud Infrastructure (OCI) account. The Pulumi installation guide and Oracle Cloud setup guide will walk you through this process.
Pulumi Program for Deployment
Once the prerequisites are addressed, below is the Pulumi TypeScript program that outlines the steps to create an OKE cluster and deploy the
fastapi-app
Helm chart on it.Ensure that you have the necessary OCI provider configurations in place, such as the region, tenancy OCID, user OCID, private key path, and fingerprint.
Let's create a new Pulumi project and write our deployment code:
import * as pulumi from "@pulumi/pulumi"; import * as oci from "@pulumi/oci"; import * as kubernetes from "@pulumi/kubernetes"; // Define a new OCI Kubernetes cluster const cluster = new oci.containerservice.Cluster("fastapiAppCluster", { // specify your cluster configuration here // Some essential parameters you might need include: // compartmentId: "your-compartment-ocid", // kubernetesVersion: "v1.XX.X", // specify the desired Kubernetes version // name: "fastapi-app-cluster", // ... }); // Define the Kubernetes provider to interact with the OKE cluster const k8sProvider = new kubernetes.Provider("k8sProvider", { kubeconfig: cluster.kubeConfig.content, }); // Deploy the fastapi-app Helm chart const fastapiAppChart = new kubernetes.helm.v3.Chart("fastapiApp", { chart: "fastapi-app", // Specify the Helm repository here if it's not a stable chart, e.g.: // repo: "https://your-repo-url/", values: { // provide any values to customize the chart installation // replicaCount: 2, // image: { // repository: "your-image-repo", // tag: "your-image-tag", // }, // service: { // type: "LoadBalancer", // port: 80, // }, // ... }, }, { provider: k8sProvider }); // Export the public IP address of the LoadBalancer, if created by the Helm chart export const publicIp = fastapiAppChart.getResourceProperty("v1/Service", "fastapi-app", "status").apply(status => status.loadBalancer.ingress[0].ip);
Explanation
- We begin by importing the necessary Pulumi libraries for OCI and Kubernetes.
- We define a Kubernetes cluster using
oci.containerservice.Cluster
. We need to specify the compartment OCID, Kubernetes version, and other properties for our OKE cluster. You will need to provide these details based on your OCI configuration. - We create a
kubernetes.Provider
instance that uses the kubeconfig of our newly created OKE cluster. This allows Pulumi to communicate with our cluster. - We then use
kubernetes.helm.v3.Chart
to deploy thefastapi-app
Helm chart onto the cluster. This assumes thatfastapi-app
is available in the configured Helm repository. Replace the chart and repo properties if your Helm chart is hosted at a different location. - Finally, if the Helm chart exposes a LoadBalancer service, we export the public IP address so it can be easily accessed. If the service type isn't LoadBalancer or you have different requirements, you can adjust the service type and port in the
values
section.
To run this program:
- Save the code to a file named
index.ts
in a new Pulumi project directory. - Run
pulumi up
to preview and deploy the changes. Pulumi will show you a preview of the resources that will be created and prompt you to confirm before making any changes.
Please ensure you have the OCI CLI installed and configured correctly, as Pulumi relies on it to manage and provision resources in Oracle Cloud. With these steps followed, you should have a running instance of your
fastapi-app
on Oracle Kubernetes Engine.