Deploy the alpine helm chart on Oracle Kubernetes Engine (OKE)
TypeScriptTo deploy the Alpine Helm chart on Oracle Kubernetes Engine (OKE), you'll need to write a Pulumi program that does the following:
- Sets up a Kubernetes cluster on Oracle Cloud Infrastructure (Oracle Kubernetes Engine).
- Installs the Helm chart for Alpine into that cluster.
In this Pulumi program, we'll be using the Pulumi OCI and Kubernetes providers. The OCI provider will be used to provision the Kubernetes cluster on Oracle Cloud Infrastructure, and the Kubernetes provider will be used to deploy the Alpine Helm chart to the cluster.
Before you run the following program, make sure you have the following prerequisites:
- A Pulumi account and the Pulumi CLI installed.
- Access to Oracle Cloud Infrastructure with the necessary IAM permissions to create OKE clusters.
- Oracle Cloud Infrastructure CLI configured with the necessary credentials.
- Helm CLI installed if you intend to fetch Helm chart details outside of Pulumi.
Below is the TypeScript Pulumi program:
import * as pulumi from "@pulumi/pulumi"; import * as oci from "@pulumi/oci"; import * as k8s from "@pulumi/kubernetes"; // Create an Oracle Kubernetes Engine (OKE) cluster const cluster = new oci.containerengine.Cluster("my-oke-cluster", { /* Required configurations like compartmentId, vcnId, etc. should be added here. Ensure to replace placeholder values with actual ones relevant to your account. */ // compartmentId: pulumi.output(oci.core.Compartment.get(/* ... */)).id, // The OCID for the compartment // vcnId: pulumi.output(oci.core.Vcn.get(/* ... */)).id, // The OCID for the VCN // Add other required properties like `kubernetesVersion`, `options`, `name`, etc. }); // Define the Kubeconfig to access the OKE cluster const kubeconfig = pulumi. all([cluster.name, cluster.kubernetesVersion]). apply(([name, version]) => { /* Kubeconfig generation logic based on the cluster details goes here... This will typically involve invoking the OCI CLI or using the OCI API. */ }); // Create a Kubernetes provider instance using the generated kubeconfig const k8sProvider = new k8s.Provider("k8s-provider", { kubeconfig: kubeconfig, }); // Deploy the Alpine Helm chart using the Kubernetes provider const alpineChart = new k8s.helm.v3.Chart("alpine", { chart: "alpine", fetchOpts: { repo: "https://charts.bitnami.com/bitnami", // specify the Helm chart repository here }, // Version can be specified if needed. Otherwise, it will deploy the latest chart version. // version: "x.y.z", }, { provider: k8sProvider }); // Export the cluster name and the status of the Helm deployment export const clusterName = cluster.name; export const alpineChartStatus = alpineChart.status;
Explanation
-
We use the
oci.containerengine.Cluster
resource (oci.ContainerEngine.Cluster) to create a new Oracle Kubernetes Engine cluster. This requires configurations such as the compartment ID and the VCN ID. -
We generate kubeconfig for the OKE cluster to access it using the Kubernetes provider. This typically involves interacting with the OCI API or running the OCI CLI commands to fetch the kubeconfig file contents.
-
We then instantiate the Kubernetes provider (
k8s.Provider
) with the generated kubeconfig. This provider will be used to deploy resources to the OKE cluster. -
Finally, we deploy the Alpine Helm chart using
k8s.helm.v3.Chart
(kubernetes.helm.sh/v3.Chart), specifying the chart name, and optionally, the repo and version. Theprovider
option specifies which Kubernetes provider to use for deploying the chart. -
The resulting cluster name and the status of the Helm chart deployment are exported as stack outputs.
Remember to fill in the placeholder values with actual data from your Oracle Cloud Infrastructure. You will use the command
pulumi up
in the terminal within the directory of this Pulumi program to create the Kubernetes cluster and deploy the chart.