Deploy the httpd helm chart on Azure Managed Openshift Service
TypeScriptTo deploy the
httpd
Helm chart on an Azure Managed OpenShift Service, we will walk through a simple program with Pulumi using TypeScript. Our program will perform the following steps:- Create an Azure Managed OpenShift Cluster.
- Deploy the
httpd
Helm chart using the Pulumi Kubernetes provider and Helm package.
Before you begin, make sure you have the following prerequisites in place:
- A Pulumi account with the CLI installed and configured with your account.
- Access to an Azure subscription and the Azure CLI installed and logged in.
- The
kubectl
CLI installed to interact with Kubernetes clusters.
Firstly, we will create an Azure Managed OpenShift Cluster. For this, we use the
OpenShiftManagedCluster
class from theazure-native
provider. This will set up the infrastructure required to run our OpenShift cluster.After the cluster is up and running, we will deploy the
httpd
Helm chart. Pulumi's Kubernetes provider can deploy applications using theChart
resource from thehelm.sh
package, which allows us to deploy any Helm chart into our Kubernetes cluster.Let's go through the Pulumi program.
import * as azure from "@pulumi/azure-native"; import * as k8s from "@pulumi/kubernetes"; import * as pulumi from "@pulumi/pulumi"; // Step 1: Create an Azure Managed OpenShift Cluster const resourceGroup = new azure.resources.ResourceGroup("myResourceGroup"); const openshiftManagedCluster = new azure.containerservice.OpenShiftManagedCluster("myOpenShiftCluster", { resourceGroupName: resourceGroup.name, location: resourceGroup.location, // We'll use the location of the resource group for our cluster. openShiftVersion: "4.3", // Specify your desired OpenShift version. // Define master and worker profiles, other required parameters are defined with default values for simplicity. masterPoolProfile: { name: "master", // Name of the master pool. count: 1, // Number of master nodes (keep it small for cost-saving, yet for production use you may need more). vmSize: "Standard_D4s_v3" // Size of the VMs. }, agentPoolProfiles: [{ name: "agentpool", // Name of the agent pool. count: 2, // Number of agents (these are your worker nodes). vmSize: "Standard_D4s_v3", // Size of the VMs. role: "compute", // Role of the agent pool, 'compute' for worker nodes. }], }); // Export the kubeconfig of the Managed OpenShift Cluster export const kubeconfig = openshiftManagedCluster.config; // Step 2: Deploy the httpd Helm Chart into Azure Managed OpenShift Service const myCluster = new k8s.Provider("myK8sProvider", { kubeconfig: openshiftManagedCluster.config, }); const httpdChart = new k8s.helm.v3.Chart("httpdChart", { chart: "httpd", version: "0.3.2", // Make sure this is the version you wish to deploy. fetchOpts: { repo: "https://charts.bitnami.com/bitnami", }, }, { provider: myCluster }); // Export the public endpoint of the httpd service export const httpdServiceEndpoint = httpdChart.getResourceProperty("v1/Service", "httpd", "status");
In the above program:
- We initialize a new resource group which will contain our Openshift cluster.
- We then use the
OpenShiftManagedCluster
class from theazure-native
provider to create our OpenShift cluster. We specify the OpenShift version, the size of the master, and worker node VMs, and the number of nodes. - The
kubeconfig
is exported, which allows you to usekubectl
to interact with the cluster outside of Pulumi programs. - Next, we create a Pulumi Kubernetes provider that uses the kubeconfig from our managed cluster.
- We then declare a Helm chart resource using the Pulumi Kubernetes provider to deploy the
httpd
Chart, from Bitnami's Helm repository. - Finally, we export the service endpoint of our
httpd
deployment. You can use this URL to access yourhttpd
service externally.
To run this program:
- Save the code to a file with a
.ts
extension, e.g.,deploy-httpd-openshift.ts
. - Use
cd
to change into the directory containing your file. - Run
pulumi up
to launch the program. Pulumi will print out the expected state and ask for confirmation before provisioning resources.
Please note, provisioning a managed OpenShift cluster on Azure may take some time, and costs will be incurred on your Azure account. Be sure to destroy the resources with
pulumi destroy
once you no longer need them to avoid extra charges.