Deploy the bookinfo helm chart on Opensshift
TypeScriptDeploying a Helm chart on an OpenShift cluster using Pulumi involves several steps. In this case, we're specifically looking at deploying the "bookinfo" Helm chart. The
bookinfo
Helm chart is a popular example application provided by Istio, and it generally consists of several microservices that work together to form a comprehensive application.Below is a TypeScript program for Pulumi that demonstrates how to deploy a Helm chart to an OpenShift cluster. Make sure you have the OpenShift cluster already running and Pulumi configured with the necessary credentials to interact with your OpenShift install.
First, we will include the necessary Pulumi Kubernetes provider which allows us to perform operations on Kubernetes resources including an OpenShift cluster. We will use the
kubernetes.helm.v3.Chart
resource to deploy the Helm chart.Here's what you need to do:
- Set up your Pulumi project and stack if you haven't already.
- Install
@pulumi/kubernetes
package usingnpm
oryarn
. - Use the
kubernetes.helm.v3.Chart
resource to specify the deployment of thebookinfo
Helm chart.
Let's start with the program:
import * as k8s from "@pulumi/kubernetes"; // Retrieve the OpenShift cluster's kubeconfig. For production scenarios, // it is safer to use the Pulumi config to pass the kubeconfig or other // sensitive data. const kubeconfig = process.env.KUBECONFIG; // Create a provider for the OpenShift cluster. const openshiftProvider = new k8s.Provider("openshift-provider", { kubeconfig: kubeconfig, }); // Deploy the 'bookinfo' Helm chart. const bookinfoChart = new k8s.helm.v3.Chart("bookinfo", { repo: "https://istio.github.io/istio-release/releases/1.3.0/charts/", chart: "bookinfo", version: "1.3.0", namespace: "bookinfo-namespace", }, { provider: openshiftProvider }); // Export the front-end service URL by querying the deployed services and fetching the load balancer IP or hostname. export const frontendServiceUrl = bookinfoChart.getResourceProperty("v1/Service", "bookinfo-details", "status").apply(status => status.loadBalancer.ingress[0].hostname || status.loadBalancer.ingress[0].ip);
The program begins by importing the
@pulumi/kubernetes
library, which contains the necessary classes and functions to interact with Kubernetes resources.Next, we retrieve the kubeconfig necessary to communicate with the OpenShift cluster. This should be securely managed and in a production environment, you would typically use Pulumi's configuration system to handle sensitive data.
We then define a
Provider
for Kubernetes, which tells Pulumi how to communicate with the OpenShift cluster. We pass along the kubeconfig we obtained earlier.The
bookinfoChart
is created using theChart
resource from the Helm package available in Pulumi's Kubernetes library. We specify the chart repository, the chart name (bookinfo
), and the chart version. Note that you should replace"https://istio.github.io/istio-release/releases/1.3.0/charts/"
with the correct Helm chart repository for Bookinfo.Lastly, we export the front-end service URL. The
getResourceProperty
function is used here to query the service object and extract the necessary information to form the URL.Make sure to replace the
chart
andversion
with the appropriate values for thebookinfo
Helm chart you wish to deploy. Additionally, you may need to customize thenamespace
based on your specific needs.To apply this Pulumi program and deploy the chart, you would execute
pulumi up
in your terminal, assuming you have the Pulumi CLI installed and configured. Ensure that your kubeconfig is properly set either in your environment or in the Pulumi configuration.Remember, when running this in a production environment, be sure to properly handle sensitive information such as kubeconfig and consider using features like secrets management provided by Pulumi.