Deploy the nginxdemo helm chart on Opensshift
TypeScriptTo deploy the nginxdemo Helm chart on an OpenShift cluster using Pulumi, we'll use the
kubernetes.helm.v3.Chart
resource from the Pulumi Kubernetes provider. Helm charts help define, install, and upgrade even the most complex Kubernetes applications.Before running this code, make sure you have access to an OpenShift cluster and have configured your
kubectl
to point to it. This is necessary because Pulumi uses the Kubernetes context fromkubectl
to interact with your cluster.Here's the TypeScript program that deploys the nginxdemo Helm chart:
import * as k8s from "@pulumi/kubernetes"; // Create a namespace for the nginxdemo Helm chart const namespace = new k8s.core.v1.Namespace("nginxdemo-namespace", { metadata: { name: "nginxdemo" } }); // Deploy the nginxdemo Helm chart const nginxdemoChart = new k8s.helm.v3.Chart("nginxdemo", { repo: "bitnami", chart: "nginx", version: "9.3.0", // Replace with the version of your choice namespace: namespace.metadata.name, fetchOpts:{ repo: "https://charts.bitnami.com/bitnami", }, }, { dependsOn: [namespace] }); // Export the namespace and chart name export const nginxdemoNamespace = namespace.metadata.name; export const chartName = nginxdemoChart.name;
Explanation
Let's understand what's happening in the program:
- We import the Pulumi Kubernetes package, which allows us to interact with Kubernetes resources.
- We create a Kubernetes namespace called
nginxdemo-namespace
where we will deploy our Helm chart. It's best practice to deploy applications within their namespaces for better organization and security. - We create a
Chart
resource using thekubernetes.helm.v3.Chart
class. In the parameters, we specify:- The repository that contains the chart (
bitnami
in this case). - The name of the Helm chart (
nginx
) which is part of the bitnami collection. - The version of the chart to use (in this case,
9.3.0
- you may need to update this to the version you wish to deploy). - The namespace where the chart will be deployed, which we reference from the created namespace object.
- Additional fetch options such as the URL of the Helm repository.
- The repository that contains the chart (
- We use a dependency declaration
{ dependsOn: [namespace] }
to ensure that the Helm chart deployment waits until the namespace is created before it begins. - We export two variables:
nginxdemoNamespace
andchartName
. These exports allow us to retrieve the namespace and the release name from the Pulumi deployment if needed. For instance, you could use these names to interact with the deployment usingkubectl
.
Make sure to install the necessary Pulumi and Kubernetes client packages before running this Pulumi program. This program will deploy the nginxdemo using the specified Helm chart to your OpenShift cluster.
After running the Pulumi program, you can verify the deployment by checking the resources within the
nginxdemo
namespace withkubectl get all -n nginxdemo
.The version number
9.3.0
is given as an example; you should replace it with the actual version number you intend to use. The repository bitnami may or may not contain a chart namednginx
, which is also used as an example. If you want to deploy a particular application chart known asnginxdemo
, ensure that you know the correct repository that hosts the chart, the correct chart name, and version.Please refer to the Bitnami charts repository at https://github.com/bitnami/charts, if you are specifically looking for Bitnami Helm charts for usage with OpenShift or Kubernetes.