Deploy the mx-api helm chart on Opensshift
TypeScriptTo deploy the
mx-api
Helm chart on an OpenShift cluster with Pulumi, we will use thekubernetes
package. Thekubernetes.helm.sh/v3.Chart
resource allows us to deploy Helm charts on any Kubernetes cluster, including an OpenShift cluster.Below is a Pulumi TypeScript program that deploys the
mx-api
Helm chart. First, let's go through what the program does:- Imports - We import the necessary Pulumi Kubernetes library.
- Helm Chart - We define a Helm Chart resource, which represents the
mx-api
chart. - Helm Chart Configuration - We need to specify the chart name, version, repository, and any custom values you might want to apply.
Make sure you have Pulumi installed and your OpenShift cluster configured as a context in your
kubeconfig
file. Pulumi will use it to communicate with your OpenShift cluster.import * as k8s from "@pulumi/kubernetes"; // Deployment of 'mx-api' helm chart on OpenShift cluster // Replace these values with the appropriate information for the 'mx-api' Helm chart. // The chart name is assumed to be 'mx-api', and it's sourced from a hypothetical Helm repository 'my-helm-repo'. const chartName = "mx-api"; const chartVersion = "1.2.3"; // specify the version of the chart const chartRepo = "http://my-helm-repo.com/charts"; // specify the chart repository // In case you have custom values you wish to define for your Helm Chart deployment, you can define them here. const customValues = { key: "value", // Example configuration. Replace with actual values // Add any other custom configuration specific to mx-api. }; // Create a Helm Chart resource for the mx-api. const mxApiChart = new k8s.helm.sh.v3.Chart(chartName, { chart: chartName, version: chartVersion, fetchOpts:{ repo: chartRepo, }, values: customValues, // If the mx-api chart must be deployed in a specific namespace, uncomment and set the following line: // namespace: "target-namespace", }); // Export the application URL by querying your OpenShift cluster (you might need to change this depending on your use case). export const mxApiUrl = mxApiChart.getResourceProperty("v1/Service", "mx-api", "status").apply(status => status.loadBalancer.ingress[0].hostname);
Here's what each section of the Pulumi program does:
-
We define
chartName
with the name of the Helm chart,chartVersion
with the version of the Helm chart you want to install, andchartRepo
with the Helm repository URL where the chart can be found. -
customValues
represents the configuration for the Helm chart. This is where you can specify any custom configuration needed for themx-api
chart. These values will override the defaults set by the Helm chart. -
The
k8s.helm.sh/v3.Chart
resource definition is where the deployment actually takes place. Here, you will pass the name, the version, and fetch options pointing to the Helm repository containing your chart. -
Lastly, we export a
mxApiUrl
, which attempts to determine the URL to access themx-api
service. Be aware that depending on your service configuration within the Helm chart (ClusterIP
,NodePort
,LoadBalancer
, etc.), the way of obtaining the URL may differ.
Before running the program, make sure your Pulumi CLI is logged in by running
pulumi login
, and your OpenShift CLI is authenticated to the cluster withoc login
. Then, you can simply runpulumi up
to preview and deploy the resources defined in this program.Keep in mind that OpenShift's RBAC and security configurations may require additional setup. For example, if the chart binds to privileged ports or the deployed services require specific security contexts, you may have to grant appropriate permissions or modify the chart's default templates accordingly.