Deploy the pdn-server helm chart on Kubernetes
TypeScriptTo deploy a Helm chart on Kubernetes using Pulumi, we can use the
Chart
resource from Pulumi's Kubernetes package. This allows us to specify the Helm chart we want to deploy, as well as configuration options like values, versions, and namespaces.In the following Pulumi program, we will deploy a Helm chart named
pdn-server
. This example assumes that the chart is available in a Helm repository that we have access to. If the chart is located in a private repository, you would need to add the repository credentials.The
Chart
resource requires us to set a few parameters:chart
: The name of the Helm chart we want to deploy.version
: The version of the chart to deploy. If omitted, the latest version will be deployed.namespace
: The Kubernetes namespace to which we want to deploy the chart. If omitted, it will be deployed to the default namespace.values
: A set of configuration values for the Helm chart. These values correspond to thevalues.yaml
file in a traditional Helm setup.
Here's a Pulumi program in TypeScript to deploy the
pdn-server
Helm chart:import * as k8s from "@pulumi/kubernetes"; // Create a Kubernetes Namespace const ns = new k8s.core.v1.Namespace("pdn-server-namespace", { metadata: { name: "pdn-server-ns" } }); // Deploy the pdn-server Helm chart const pdnServerChart = new k8s.helm.v3.Chart("pdn-server-chart", { chart: "pdn-server", version: "1.2.3", // Replace with the desired chart version namespace: ns.metadata.name, // If you have custom values you can specify them as an object values: { // Custom values go here. For example: // serviceType: "LoadBalancer", // replicaCount: 3, }, // Uncomment the following line if your Helm chart is in a private repository // fetchOpts: { repo: "https://your-private-helm-repo.com/" }, }, { dependsOn: [ns] }); // Export the Namespace name export const namespaceName = ns.metadata.name; // Export the Service name and IP address of the pdn-server (if applicable) export const pdnServerService = pdnServerChart.getResourceProperty("v1/Service", "pdn-server", "status");
Here's what this program does, step by step:
- It imports the necessary Kubernetes package from Pulumi.
- It creates a new Kubernetes namespace
pdn-server-ns
where we will deploy our Helm chart. Namespaces allow you to partition your Kubernetes cluster into sub-clusters. - It declares the
pdn-server-chart
chart from the Helm repository and specifies its version. - It optionally includes custom
values
, corresponding to configurations in the Helm chart'svalues.yaml
file. This is commented out in the example as it requires knowledge of the specific chart you're deploying. - It (optionally) sets
fetchOpts
with the repository URL if the chart is in a private repository. - It adds an explicit dependency using
{ dependsOn: [ns] }
to ensure that the namespace is created before the chart is deployed. - It exports the namespace name and any service endpoint information that may be part of the
pdn-server
Helm chart so you can easily retrieve it from the Pulumi stack outputs.
To run this program, save it in a TypeScript file, for example
index.ts
, then use the Pulumi CLI to create a new stack and deploy it:pulumi stack init dev pulumi up
The
pulumi up
command will compile the TypeScript program into JavaScript, show you a preview of the resources that will be created, and ask for confirmation before proceeding with the deployment. After confirming, Pulumi will deploy thepdn-server
Helm chart to your Kubernetes cluster.Remember to replace the placeholder values, such as the chart version and any custom values, with the actual values for your use case. If using a private Helm repository, provide the
repo
option within thefetchOpts
field.