Deploy the wordpress-nginx helm chart on Azure Managed Openshift Service
TypeScriptTo deploy the WordPress-Nginx helm chart on Azure Managed OpenShift Service, you will need to create an OpenShift cluster on Azure and then use the Helm chart resource to deploy WordPress with Nginx. In this guide, I will show you how to:
- Create an Azure Red Hat OpenShift cluster using the
azure-native.containerservice.OpenShiftManagedCluster
resource. - Deploy the WordPress-Nginx Helm chart on the cluster using the
kubernetes.helm.v3.Chart
resource.
Step 1: Create the Azure Red Hat OpenShift Cluster
You will need to create an instance of
OpenShiftManagedCluster
. The constructor requires parameters such as location, resource name, and properties that define the specifics of the OpenShift Managed Cluster including the network profile, master pool profile, and agent pool profiles where your applications will run.Step 2: Deploy the WordPress-Nginx Helm Chart
Once the OpenShift cluster is up and running, you can configure Pulumi to use the Kubernetes provider to interact with the cluster and deploy applications using Helm charts. The
kubernetes.helm.v3.Chart
resource will help you to deploy WordPress-Nginx Helm chart to your cluster.In the Pulumi program below, replace placeholders such as
<RESOURCE_GROUP_NAME>
,<CLUSTER_NAME>
, and<LOCATION>
with your desired Azure resource group name, OpenShift cluster name, and Azure location respectively.import * as azure_native from "@pulumi/azure-native"; import * as k8s from "@pulumi/kubernetes"; import * as pulumi from "@pulumi/pulumi"; // Create an Azure Resource Group const resourceGroup = new azure_native.resources.ResourceGroup("<RESOURCE_GROUP_NAME>"); // Create an Azure Red Hat OpenShift cluster const openshiftCluster = new azure_native.containerservice.OpenShiftManagedCluster("<CLUSTER_NAME>", { // Required properties resourceName: "<CLUSTER_NAME>", resourceGroupName: resourceGroup.name, location: "<LOCATION>", openShiftVersion: "latest", // Specify the OpenShift version // Define the master profile (e.g., count, vm size, subnet cidr) // Define network profile (e.g., vnet id, vnet cidr) // Define agent pool profiles (e.g., name, count, vm size, os type) // ... }, { dependsOn: resourceGroup }); // Use the OpenShift cluster credentials to configure the Kubernetes provider const creds = pulumi.output(azure_native.containerservice.listOpenShiftManagedClusterUserCredentials({ resourceName: openshiftCluster.name, resourceGroupName: resourceGroup.name, })); const kubeconfig = creds.kubeconfigs[0].kubeconfig.apply((encodedConfig) => Buffer.from(encodedConfig, "base64").toString()); const k8sProvider = new k8s.Provider("openshiftK8s", { kubeconfig: kubeconfig, }); // Deploy the WordPress-Nginx Helm chart using the Kubernetes provider const wordpressNginxChart = new k8s.helm.v3.Chart("wordpress-nginx", { chart: "wordpress", version: "latest", // Specify the chart version namespace: "default", // Specify the namespace if not 'default' values: { // Set Nginx as the web server, and any other custom values // You can set specific versions of WordPress and Nginx or customize other values }, }, { provider: k8sProvider }); // Export the public URL of the WordPress-Nginx deployment const wordpressUrl = wordpressNginxChart.getResourceProperty("v1/Service", "wordpress-nginx", "status").apply(status => status.loadBalancer.ingress[0].ip || status.loadBalancer.ingress[0].hostname); export const endpointUrl = pulumi.interpolate`http://${wordpressUrl}`;
Explanation:
-
We start by creating a resource group to contain all of our Azure resources.
-
The
OpenShiftManagedCluster
resource creates the managed OpenShift cluster in Azure. ThedependsOn
option ensures the resource group is created before the OpenShift cluster. -
The
listOpenShiftManagedClusterUserCredentials
function retrieves the credentials we need to interact with the OpenShift cluster. -
The
k8s.Provider
resource sets up the Kubernetes provider using the kubeconfig from the OpenShift cluster, allowing us to deploy applications on it. -
The
k8s.helm.v3.Chart
resource installs the WordPress-Nginx Helm chart on the OpenShift cluster. -
Finally, we export the endpoint URL where the WordPress-Nginx application will be accessible.
You will need to ensure that your Pulumi stack is correctly configured with the necessary Azure credentials, and that you have the appropriate permissions to create and manage Azure Red Hat OpenShift clusters and deployments.
Please refer to the Pulumi Azure documentation for guidance on configuring your Azure credentials with Pulumi.
- Create an Azure Red Hat OpenShift cluster using the