Deploy the speedtest-tracker helm chart on Oracle Kubernetes Engine (OKE)
TypeScriptDeploying the
speedtest-tracker
helm chart on Oracle Kubernetes Engine (OKE) involves several steps in Pulumi. Firstly, you need to have an OKE cluster set up and ready for deployment. This code assumes you have already provisioned an OKE cluster. Next, we will deploy thespeedtest-tracker
Helm chart into this existing cluster.Below is a TypeScript program that demonstrates how to deploy a Helm chart to an Oracle Kubernetes Engine instance using Pulumi.
First, we will import the necessary Pulumi libraries to interact with Kubernetes resources. We will use the
@pulumi/kubernetes
package, which provides the ability to declare Kubernetes resources using Pulumi. Then, we'll write the necessary code to deploy the Helm chart.Here is the complete Pulumi program that does this:
import * as pulumi from "@pulumi/pulumi"; import * as k8s from "@pulumi/kubernetes"; // Step 1: Provide the existing OKE cluster's kubeconfig // This should be securely retrieved. For this example, it's hardcoded, // but you should use Pulumi's Config or other secure storage for this data. const kubeconfig = '<Your OKE Cluster Kubeconfig>'; // Step 2: Create a Provider for the existing OKE cluster. const provider = new k8s.Provider("oke-k8s-provider", { kubeconfig: kubeconfig, }); // Step 3: Define the helm chart for the speedtest-tracker application. const speedtestTrackerChart = new k8s.helm.v3.Chart("speedtest-tracker-chart", { // Assume the Helm chart is available in a chart repository // Replace with the correct repository and chart details if different chart: "speedtest-tracker", version: "1.0.0", // specify the exact chart version fetchOpts: { repo: "http://helm.robotech-cloud.com/", // specify the chart repository }, }, { provider: provider }); // Export the name of the chart we just deployed export const chartName = speedtestTrackerChart.metadata.apply(m => m.name);
In this program:
-
We imported the
@pulumi/kubernetes
package to interact with Kubernetes resources, including deploying Helm charts. -
We defined the kubeconfig for the existing OKE cluster. This kubeconfig is necessary for Pulumi to interact with your Kubernetes cluster. In a production environment, this data should be retrieved securely, using Pulumi's Config or even stored in a managed secret storage provider.
-
We instantiated a Kubernetes provider for the OKE cluster using the kubeconfig. This provider ensures that Pulumi communicates with the OKE cluster to deploy the
speedtest-tracker
chart. -
We declared a Helm chart resource (of the version v3) using
new k8s.helm.v3.Chart
. In this declaration;"speedtest-tracker-chart"
is a name we assign to the Pulumi resource.chart
specifies the chart name to be deployed. We've used"speedtest-tracker"
.version
specifies the exact version of the chart to deploy.fetchOpts
provides details about the repository where the Helm chart is hosted so that Pulumi knows where to fetch the chart from.- We use
provider
to inform Pulumi that this Helm chart should be deployed using the previously defined OKE Kubernetes provider.
-
Finally, we're exporting
chartName
, which allows us to see the name of the chart we deployed directly from the Pulumi stack outputs.
To use this Pulumi program:
- Replace
'<Your OKE Cluster Kubeconfig>'
with the actual kubeconfig for your OKE cluster. - Ensure that the
chart
andversion
correspond to thespeedtest-tracker
chart you want to deploy. If it's hosted in a different repository, use the appropriatefetchOpts
to point to that repository.
To run this Pulumi program, you would typically use the Pulumi CLI to deploy it:
pulumi up
This command will provision the resources as defined by the program, and you'll be able to see the outputs and infrastructure changes that will be applied.
Remember, when working with cloud resources, ensure that you manage your secrets (like kubeconfig) securely. Pulumi provides a secrets management system that encrypts secret data at rest and in transit.
-