Deploy the wiremock helm chart on Azure Managed Openshift Service
TypeScriptTo deploy the WireMock Helm chart on an Azure Managed OpenShift service using Pulumi, you'll undertake the following steps:
- Define an Azure Managed OpenShift cluster using the
azure-native.containerservice.OpenShiftManagedCluster
resource. - Deploy the Helm chart using the
kubernetes.helm.v3.Chart
resource, which requires that you have your Kubernetes configuration set up to connect to the OpenShift cluster.
Here's a Pulumi program, written in TypeScript, that accomplishes these tasks:
import * as pulumi from "@pulumi/pulumi"; import * as azure_native from "@pulumi/azure-native"; import * as k8s from "@pulumi/kubernetes"; // Step 1: Create an Azure Managed OpenShift cluster const resourceGroupName = "myResourceGroup"; const openshiftManagedClusterName = "myOpenShiftCluster"; // Create an Azure Resource Group const resourceGroup = new azure_native.resources.ResourceGroup(resourceGroupName, { resourceGroupName: resourceGroupName, }); // Create an Azure OpenShift Managed Cluster const openshiftManagedCluster = new azure_native.containerservice.OpenShiftManagedCluster(openshiftManagedClusterName, { resourceName: openshiftManagedClusterName, resourceGroupName: resourceGroup.name, location: resourceGroup.location, openShiftVersion: "v4.6", networkProfile: { vnetCidr: "10.0.0.0/8", }, masterPoolProfile: { // Required for master node configuration count: 3, vmSize: "Standard_D4s_v3", }, // Required configuration for cluster authentication authProfile: { identityProviders: [{ name: "Azure AD", provider: { clientId: "<AZURE_AD_CLIENT_ID>", secret: "<AZURE_AD_SECRET>", tenantId: "<AZURE_AD_TENANT_ID>", }, }] }, agentPoolProfiles: [{ // Required for worker nodes configuration name: "default", count: 3, vmSize: "Standard_D4s_v3", osType: "Linux", role: "compute", }], }); // Step 2: Deploy the Wiremock Helm chart // Establish a connection to the kubernetes cluster const kubeconfig = openshiftManagedCluster.kubeconfig.apply(JSON.stringify); // Create a kubernetes provider instance using the above kubeconfig const k8sProvider = new k8s.Provider("k8sProvider", { kubeconfig: kubeconfig, }); // Deploy the Wiremock helm chart const wiremockChart = new k8s.helm.v3.Chart("wiremock", { chart: "wiremock", version: "5.1.0", // Specify the version of the Helm chart here namespace: "default", // Specify the namespace or create a new one if needed fetchOpts: { repo: "https://center.helm.sh/charts/" }, // Replace with the official Wiremock Helm chart repository if different }, { provider: k8sProvider }); // Export the URL endpoint for the Wiremock service export const wiremockUrl = pulumi.interpolate `http://${wiremockChart.getResourceProperty("v1/Service", "wiremock", "status").loadBalancer.ingress[0].hostname}`;
Explanation
In the code provided:
- We start by creating an Azure Resource Group to contain our resources using
azure_native.resources.ResourceGroup
. - We then define an
OpenShiftManagedCluster
which represents our Azure Red Hat OpenShift cluster. This cluster needs a certain number of master and worker nodes, specified inmasterPoolProfile
andagentPoolProfiles
respectively. - The cluster's authentication profile is configured to use Azure AD with
authProfile
. You should replace<AZURE_AD_CLIENT_ID>
,<AZURE_AD_SECRET>
, and<AZURE_AD_TENANT_ID>
with your actual Azure AD credentials. - We capture the
kubeconfig
from our cluster, which allows us to interact with the Kubernetes API server running on the OpenShift cluster. - A Kubernetes
Provider
is then instantiated using thekubeconfig
, allowing Pulumi to operate on the Kubernetes cluster. - We use the
helm.v3.Chart
resource to deploy the WireMock Helm chart to thedefault
Kubernetes namespace. You'll have to specify the correct version number for the Wiremock Helm chart and the chart repository URL. - Lastly, we export the load balancer URL that would be assigned once the Wiremock service is up and running.
Note: You would need to have the Pulumi CLI set up with appropriate cloud provider credentials, and the
@pulumi/azure-native
and@pulumi/kubernetes
packages installed. Before running the program, ensure that the Helm chart version and repository are correct and that the Azure AD credentials are properly set.- Define an Azure Managed OpenShift cluster using the