Deploy the simple-grafana helm chart on Oracle Kubernetes Engine (OKE)
TypeScriptTo deploy the
simple-grafana
Helm chart on Oracle Kubernetes Engine (OKE) using Pulumi, you need to perform several tasks:- Set up the Oracle Kubernetes Engine (OKE) cluster.
- Configure Pulumi to use the
oci
andkubernetes
providers to interact with Oracle Cloud Infrastructure and Kubernetes, respectively. - Create a Kubernetes configuration that allows Pulumi to connect to your OKE cluster.
- Use the
kubernetes.helm.v3.Chart
resource to deploy thesimple-grafana
Helm chart to your OKE cluster.
We will go through each step, providing a Pulumi program that accomplishes this.
Step 1: Set up an OKE Cluster
If you don't already have an OKE cluster, you can create one using the
oci.ContainerEngine.Cluster
resource. However, since setting up a new cluster is beyond the scope of deploying a Helm chart and typically done separately, in this guide, we assume you already have an OKE cluster up and running that you can connect to.Step 2: Configure Pulumi Providers
For Pulumi to connect to Oracle Cloud and your Kubernetes cluster, you need to provide the appropriate credentials. Make sure that your Oracle Cloud credentials are set up correctly in your environment, as described in the OCI Provider documentation.
Step 3: Create Kubernetes Configuration
With your OKE cluster ready, obtain the
kubeconfig
file that allows you to connect to this cluster viakubectl
. This file contains the necessary details for Pulumi's Kubernetes provider to interact with your cluster. Store the contents of yourkubeconfig
file securely and ensure it's accessible during deployment.Step 4: Deploy simple-grafana Helm Chart
Use the
kubernetes.helm.v3.Chart
resource, from the Pulumi Kubernetes provider, to deploy yoursimple-grafana
chart. In your Pulumi program, you provide the name of the chart and, optionally, any overrides for default settings you want to apply.Here's a TypeScript program showing how this could be done. Place this code in a file, such as
index.ts
, in your Pulumi project directory.import * as pulumi from "@pulumi/pulumi"; import * as oci from "@pulumi/oci"; import * as k8s from "@pulumi/kubernetes"; // Existing OKE cluster information const clusterId = "your-oke-cluster-id"; // Replace with your actual cluster ID const compartmentId = "your-oci-compartment-id"; // Replace with your actual compartment ID // Create an OCI Provider instance const ociProvider = new oci.Provider("ociProvider", { // You can set the region and other properties if needed. }); // Retrieve the kubeconfig from OCI for your existing OKE Cluster const kubeconfig = pulumi.output(oci.containerengine.getClusterKubeconfig({ clusterId: clusterId, compartmentId: compartmentId, }, { provider: ociProvider })).kubeconfig; // Create a Kubernetes provider instance using the cluster's kubeconfig const k8sProvider = new k8s.Provider("k8sProvider", { kubeconfig: kubeconfig, }); // Deploy the simple-grafana Helm chart const grafanaChart = new k8s.helm.v3.Chart("simple-grafana", { chart: "grafana", // You can specify the version of the chart and its values here // For example: // version: "6.1.0", // values: { // service: { // type: "LoadBalancer", // }, // }, // Make sure to specify the namespace if required // namespace: "default", }, { provider: k8sProvider }); // Export the service URL of Grafana export const grafanaServiceUrl = pulumi.output(grafanaChart.getResourceProperty("v1/Service", "simple-grafana-grafana", "status")) .apply(status => `http://${status.loadBalancer.ingress[0].ip}:80`);
In the program above, we're fetching the
kubeconfig
from OCI that is specific to a pre-existing OKE cluster. We then create a new instance of the Kubernetes provider using this configuration. With the provider configured, we define aChart
resource, pointing to thegrafana
Helm chart. This is synonymous with running ahelm install
command. Optionally, we include a block to set specific values for the Helm chart configuration, such as specifying service types or deploying Grafana in a specific namespace.Finally, we export the Grafana service URL, which you can use to access the Grafana dashboard once it's deployed. Remember that some configuration settings in the Helm chart, like the service type, may affect the availability of the URL, so make sure the service type corresponds with your cloud provider's capabilities (e.g. LoadBalancer).
Please make sure that the chart name 'grafana' is replaced with 'simple-grafana' or the correct chart name from your Helm repository, and also fill the
clusterId
, andcompartmentId
.To deploy this Pulumi program, place it in your Pulumi project directory, then run
pulumi up
from your terminal. Follow the prompts by Pulumi to preview and deploy your changes. After successful deployment, you can runpulumi stack output grafanaServiceUrl
to get the Grafana service URL and access your Grafana dashboard.