Deploy the wordpress-apache helm chart on Oracle Kubernetes Engine (OKE)
TypeScriptWhen deploying a Helm Chart to Oracle Kubernetes Engine (OKE) using Pulumi, we will make use of the
kubernetes.helm.v3.Chart
class from the Pulumi Kubernetes provider. This class enables us to deploy Helm charts into a Kubernetes cluster.Before you proceed with the code below, make sure you have set up the following prerequisites:
- Oracle Cloud Infrastructure (OCI) account with an active subscription.
- Oracle Kubernetes Engine (OKE) cluster already created and running.
- Pulumi CLI installed and configured to communicate with your OCI account.
- Kubernetes configuration file (
kubeconfig
) obtained from your OKE cluster and set up locally forkubectl
access.
Here is the Pulumi program in TypeScript to deploy the WordPress-Apache Helm chart to your OKE cluster:
import * as pulumi from "@pulumi/pulumi"; import * as k8s from "@pulumi/kubernetes"; // Create an instance of the k8s Provider configured with kubeconfig from your OKE cluster. // Ensure that the kubeconfig is correctly configured on your local machine where you're running Pulumi. const provider = new k8s.Provider("oke-k8s", { kubeconfig: "<your kubeconfig content>", // Replace with your actual kubeconfig content }); // Define the Helm Chart for the WordPress-Apache deployment. const wordpressChart = new k8s.helm.v3.Chart("wp-apache", { chart: "wordpress", version: "X.Y.Z", // Replace with the specific chart version you want to deploy fetchOpts: { repo: "https://charts.bitnami.com/bitnami", }, values: { // Custom values to configure WordPress. // Specify any custom values needed for your WordPress chart. // For example, you may need to provide serviceType, additional configurations like ingress, database settings, etc. service: { type: "LoadBalancer", }, // Add any additional configuration you may want to apply. }, }, { provider: provider }); // Export the endpoint of the WordPress service. // This assumes `wordpress` is the Helm Chart default service name and it's of type LoadBalancer. export const endpoint = wordpressChart.getResourceProperty("v1/Service", "wp-apache-wordpress", "status") .apply(status => status.loadBalancer.ingress[0].ip || status.loadBalancer.ingress[0].hostname);
Let's walk through what we are doing here:
- We begin by importing the necessary Pulumi packages - the core Pulumi package and the Kubernetes package.
- Next, we create a Pulumi Kubernetes Provider. This tells Pulumi how to communicate with your OKE cluster. Make sure to replace
<your kubeconfig content>
with the actual contents of your kubeconfig file. You can also manage kubeconfig more securely with Pulumi's secrets management. - We then define a Helm Chart resource for the WordPress deployment using the
k8s.helm.v3.Chart
class. We specify the name of the chart ("wordpress"
), the repository URL where it can be found, and optionally, the values that customize the deployment of the WordPress chart. You might want to specify particular configurations depending on your needs like service types (e.g., NodePort, ClusterIP, or LoadBalancer), ingress settings, etc. Remember to use the appropriate version for the helm chart by replacing"X.Y.Z"
with the chart version you wish to deploy. - Finally, we export the public endpoint of the WordPress service. This assumes that the WordPress service created by the Helm chart is named
"wordpress"
and exposes a LoadBalancer to access the WordPress site over the network. Theendpoint
will be the external IP address or the hostname provided by the LoadBalancer.
After writing the above program to a file (let's say
index.ts
), you can deploy it using Pulumi CLI with the following steps:-
Initialize a new Pulumi project:
pulumi new typescript
-
Replace the contents of
index.ts
with the program code. -
Run the Pulumi program to deploy your resources:
pulumi up
Upon successful deployment, Pulumi will output the LoadBalancer's IP or hostname, which you can use to access your WordPress site.