Deploy the kubecost helm chart on Oracle Kubernetes Engine (OKE)
TypeScriptDeploying a Helm chart on Oracle Kubernetes Engine (OKE) with Pulumi involves several steps. The process includes setting up the necessary cloud resources within Oracle Cloud Infrastructure (OCI), creating a Kubernetes cluster by using the
oci.ContainerEngine.Cluster
resource, and then deploying the Kubecost Helm chart onto that cluster. To apply a Helm chart, we use thekubernetes.helm.v3.Chart
resource from the Pulumi Kubernetes provider.Below is a conceptual overview of what you would do, step by step:
- Define an OCI Kubernetes cluster.
- Configure Kubernetes provider to connect to the newly created cluster.
- Define a Helm chart resource for Kubecost installation.
Here's a Pulumi program written in TypeScript for these steps:
import * as oci from "@pulumi/oci"; import * as k8s from "@pulumi/kubernetes"; // Step 1: Define an OCI Kubernetes cluster. const cluster = new oci.ContainerEngine.Cluster("myOkeCluster", { compartmentId: oci.config.compartmentId, // ... other necessary OKE configurations }); // Step 2: Configure Kubernetes provider to connect to the newly created cluster. const k8sProvider = new k8s.Provider("myK8sProvider", { kubeconfig: cluster.kubeconfig, // This fetches the kubeconfig from the created OKE cluster }); // Step 3: Define a Helm chart resource for Kubecost installation. const kubecost = new k8s.helm.v3.Chart("kubecost", { chart: "kubecost", version: "<chart version>", // specify the chart version fetchOpts: { repo: "https://kubecost.github.io/cost-analyzer/", // repository URL }, }, { provider: k8sProvider }); // ensure that this uses the provider that connects to our OKE cluster // Stack exports export const clusterName = cluster.name; export const kubecostChartVersion = kubecost.version;
Let's break down the code:
-
We import the necessary Pulumi packages for OCI and Kubernetes (
@pulumi/oci
and@pulumi/kubernetes
). -
We create an OKE cluster using the
oci.ContainerEngine.Cluster
resource. This will provision the Kubernetes cluster in your OCI compartment. ThecompartmentId
can be configured in your Pulumi stack configuration, but for simplicity, we're getting it from the default OCI provider configuration. To create the cluster, you will need to fill in other necessary OKE configurations. -
Once our Kubernetes cluster is set up, we need to configure a Pulumi Kubernetes provider to interact with the cluster. For this, we create a new
k8s.Provider
instance, which uses the kubeconfig from our OCI Kubernetes cluster. -
After setting up the Kubernetes provider, we proceed to deploy the Kubecost Helm chart. The
k8s.helm.v3.Chart
resource is used to reference the Helm chart from the specified repository. Replace"<chart version>"
with the actual version of the Kubecost Helm chart you wish to deploy. Therepo
option infetchOpts
specifies the Helm repository URL containing the Kubecost chart.
Finally, we export some stack outputs for easy access to important attributes, such as the cluster name and the deployed chart version. You can use these outputs for querying with the
pulumi stack output
command.This program assumes that your Pulumi CLI is already authenticated with Oracle Cloud Infrastructure, and all prerequisites such as having an OCI compartment and necessary IAM permissions are fulfilled.
Please replace placeholder values like
"<chart version>"
with actual values relevant to your use case. Additionally, you'll need to complete the OKE configuration inoci.ContainerEngine.Cluster
according to your requirements in terms of node shapes, compartment IDs, network settings, etc. For more detailed configurations, refer to the OCI ContainerEngine.Cluster documentation.