How to use the Pulumi Kubernetes provider Helm resource

How to use the Pulumi Kubernetes provider Helm resource

If you worked with Pulumi and #Kubernetes,?you probably know that?Pulumi?has?a?Kubernetes provider?that allows you to deploy Kubernetes?resources.?

But did you know that you can also use the Kubernetes provider to deploy Helm charts?

But why you want to do that??Well,?there is a couple of reasons for the why,?but the most important one for me is that you are not disconnected from the Kubernetes ecosystem.

If your organization opts to employ a generic programming language like #Golang, #Python, #TypeScript and #dotnet to deploy its infrastructure (and if not, you should seriously consider it), you might wonder if you need to rewrite all your Helm charts or the ones you're using from the community/supplier.?The answer is no!?You can use the Pulumi Kubernetes?provider to deploy Helm charts.

The benefit of #Helm resource support is that you now have an end-to-end deployment workflow for your Kubernetes infrastructure and applications.?If you're following the GitOps method, you can now use the same procedure to create a seed cluster to kick-start your GitOps process.

This post will demonstrate how to deploy a Helm chart using the Pulumi Kubernetes provider.

Never heard of Helm?

What is Helm??Helm is a package manager for Kubernetes and a Helm chart?is a collection of different Kubernetes?(like Deployment,?Service,?Ingress,?etc.)?resources that are bundled together?and can be deployed as a?unit.?

There are many ways to share Helm charts, but the most popular way is by using a Helm repository.??Recently Helm supports also OCI registries as a way to share the Helm chart as an OCI artifact.

Additionally,?Helm has a templating engine that allows you to customize the Helm chart before you deploy it.?It is based?on the go templating engine?(plus Sprig functions)?and allows you to customize the Helm chart based on your needs.?

This?templating engine is also the reason why some folks are avoiding Helm.?Things can get pretty complex if not taken care.

Prerequisites

Before we can start,?we need to fulfill some prerequisites:

  • Pulumi
  • Pulumi Account?- this optional, but convenient to handle the state of the different stacks.
  • Node, as we will use TypeScript in this blog post
  • A local Kubernetes cluster. I will use?kind?in this blog post, but you can use any Kubernetes cluster you want.

Deploying a Helm chart with Pulumi

Enough theory,?let's get our hands dirty!?First you need to create a new Pulumi project.?You can do that by using?the?pulumi new?command and select from the list of templates the?kubernetes-typescript?template.

Pulumi has lot of build-in templates,?but you can also use your own templates.?You can find more information about that?in documentation.

pulumi new kubernetes-typescript --dir helm-pulumi        

How does the provider handles?the?kubeconfig??

By default,?Pulumi will use a local kubeconfig if available,?or one can be passed as a provider argument in the?request.?In this blog post,?we will use the local kubeconfig.

You will be asked a couple of questions,?but you can just hit enter to use the default values.?Now open the?index.ts?file and add the following code:

import * as k8s from "@pulumi/kubernetes";

const helmDashboard = new k8s.helm.v3.Release("helm-dashboard", {
    name: "helm-dashboard",
    chart: "helm-dashboard",
    version: "0.1.10",
    repositoryOpts: {
        repo: "https://helm-charts.komodor.io",
    },
    namespace: "helm-dashboard",
    createNamespace: true,
});

export const dashboardName = helmDashboard.name        
If necessary,?you can provide override values for the Helm chart by using the?values?property.

My demo, will deploy the Komodor helm-dashboard project.

Helm Dashboard presents a user-friendly interface, enabling users to effortlessly visualize the installed Helm charts, access their revision history, and explore the associated Kubernetes resources.

Run the?kind create cluster?command to create a local Kubernetes cluster.

kind create cluster
Creating cluster "kind" ...
 ? Ensuring node image (kindest/node:v1.27.3) ?? 
 ? Preparing nodes ??  
 ? Writing configuration ?? 
...
Not sure what to do next? ??  Check out https://kind.sigs.k8s.io/docs/user/quick-start/        

After the cluster is created,?you can run?pulumi up?to deploy the Helm chart.

pulumi up        

You should see something like this:

pulumi up   
Previewing update (dev)

View in Browser (Ctrl+O): https://app.pulumi.com/dirien/helm-pulumi/dev/previews/e5bf2681-5d94-4ef6-9810-1de9b52c2e01

     Type                              Name             Plan       
 +   pulumi:pulumi:Stack               helm-pulumi-dev  create     
 +   └─ kubernetes:helm.sh/v3:Release  helm-dashboard   create     


Outputs:
    dashboardName: "helm-dashboard"

Resources:
    + 2 to create

Do you want to perform this update? yes
Updating (dev)

View in Browser (Ctrl+O): https://app.pulumi.com/dirien/helm-pulumi/dev/updates/1

     Type                              Name             Status            
 +   pulumi:pulumi:Stack               helm-pulumi-dev  created (27s)     
 +   └─ kubernetes:helm.sh/v3:Release  helm-dashboard   created (25s)     


Outputs:
    dashboardName: "helm-dashboard"

Resources:
    + 2 created

Duration: 29s        

You can now check if the Helm chart is deployed by running the?kubectl port-forward?command.


kubectl port-forward svc/helm-dashboard 9000:8080 -n helm-dashboard        

Now you can open your browser and navigate to?https://localhost:9000?and you should see the Helm dashboard.

No alt text provided for this image


Deploying a OCI Helm chart with Pulumi

In the previous example,?we deployed a Helm chart from a Helm repository.?Let's now deploy a Helm chart from an OCI?registry.

Add the following code to the?index.ts?file:

const nodered = new k8s.helm.v3.Release("node-red", {
    name: "node-red",
    chart: "oci://ghcr.io/schwarzit/charts/node-red",
    namespace: "node-red",
    createNamespace: true,
});        

Run?pulumi up?to deploy the new Helm chart.?We expect that the Helm chart is deployed to the?node-red?namespace.


kubectl get all -n node-red
NAME                            READY   STATUS    RESTARTS   AGE
pod/node-red-5bbcfd47ff-lfvnl   1/1     Running   0          83s

NAME               TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)    AGE
service/node-red   ClusterIP   10.96.149.5   <none>        1880/TCP   83s

NAME                       READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/node-red   1/1     1            1           83s

NAME                                  DESIRED   CURRENT   READY   AGE
replicaset.apps/node-red-5bbcfd47ff   1         1         1       83s        
No alt text provided for this image

Wrapping up

In this post,?we learned how to deploy a Helm chart using Pulumi and the Kubernetes provider in your preferred?programming language.?

This makes it easy to deploy Helm charts to your Kubernetes cluster without the need to install?the Helm CLI and leaving your Pulumi program.

No alt text provided for this image


Tyler Hayden

Cloud Infrastructure | GTM @ Pulumi

1 年

Deploying helm charts never looked so easy, nice post Engin Diri ??

要查看或添加评论,请登录

Engin Diri的更多文章

社区洞察

其他会员也浏览了