Skip to main content

Search the Dev Center

Search tutorials, templates, examples, and more.

Kubernetes OVHcloud TypeScript Starter

A TypeScript program to deploy a Kubernetes cluster on OVHcloud

Before you begin#

For this walkthrough, you'll need:

Create a new project#

This starter creates a managed Kubernetes cluster with a node pool in your OVHcloud Public Cloud project and exports the cluster’s kubeconfig and the node pool’s ID.

Terminal window
mkdir my-project; cd my-project
pulumi new kubernetes-ovh-typescript

The pulumi new command walks you through creating and configuring the new project and stack. A stack is an instance of a project, and you can have many of them (dev, staging, prod), each with its own configuration settings. Depending on the language, you may also be asked for your preferred package manager or toolchain.

Then it asks for the template’s settings. Every one has a default except ovhServiceName, the ID of your Public Cloud project:

KeyDescriptionDefault
ovhServiceNameThe OVHcloud Public Cloud Project to deploy into—
ovhRegionThe OVHcloud region to deploy intoGRA9
clusterNameName of the clustermy_desired_cluster
nodePoolNameName of the node poolmy-desired-pool
nodePoolDesiredNodesNumber of desired nodes in the cluster1
nodePoolMaxNodesNumber of max nodes in the cluster3
nodePoolMinNodesNumber of min nodes in the cluster1
flavorNameName of the flavor/type of the machineb3-8
You can change values like these later with pulumi config set :
Terminal window
pulumi config set ovhServiceName <value>
pulumi config set ovhRegion <value>
pulumi config set clusterName <value>
pulumi config set nodePoolName <value>
pulumi config set nodePoolDesiredNodes <value>
pulumi config set nodePoolMaxNodes <value>
pulumi config set nodePoolMinNodes <value>
pulumi config set flavorName <value>

When setup completes, you’ll see a few files:

  • Pulumi.yaml contains the project name and the language it’s written in.
  • Pulumi.dev.yaml contains the dev stack’s settings, including the values you just entered.
  • index.ts contains the program code that declares your cloud resources.

Take a moment to open them up and have a look. Here’s what’s in index.ts:

index.ts
import * as pulumi from "@pulumi/pulumi";
import * as ovh from "@ovhcloud/pulumi-ovh";
// Get configuration values or use defaults
const config = new pulumi.Config();
const ovhServiceName = config.require("ovhServiceName");
const ovhRegion = config.get("ovhRegion") || "GRA9";
const clusterName = config.get("clusterName") || "my_desired_cluster";
const nodePoolName = config.get("nodePoolName") || "my-desired-pool";
const nodePoolDesiredNodes = config.getNumber("nodePoolDesiredNodes") || 1;
const nodePoolMaxNodes = config.getNumber("nodePoolMaxNodes") || 3;
const nodePoolMinNodes = config.getNumber("nodePoolMinNodes") || 1;
const flavorName = config.get("flavorName") || "b3-8";
// Deploy a new Kubernetes cluster
const myKubeCluster = new ovh.cloudproject.Kube(clusterName, {
region: ovhRegion,
serviceName: ovhServiceName,
name: clusterName
});
// Export kubeconfig file
export const kubeconfig = pulumi.secret(myKubeCluster.kubeconfig)
//Create a Node Pool
const nodePool = new ovh.cloudproject.KubeNodePool(nodePoolName, {
desiredNodes: nodePoolDesiredNodes,
flavorName: flavorName,
kubeId: myKubeCluster.id,
maxNodes: nodePoolMaxNodes,
minNodes: nodePoolMinNodes,
serviceName: ovhServiceName,
});
export const nodePoolID = nodePool.id;

Deploy the project#

The OVHcloud provider needs your OVHcloud API credentials. Set them up before you deploy, as the OVH provider’s setup guide describes.

Deploy with pulumi up. It starts with a preview of what it’s about to create and asks before it changes anything. Choose yes to deploy.

The cluster and its nodes take several minutes to come up.

Pulumi adds a random suffix to most resource names, which is called autonaming. It lets you deploy the same program to more than one stack without names colliding. This program sets the cluster’s name itself from the clusterName setting, so the cluster is called my_desired_cluster unless you entered another name.

Terminal window
pulumi up

When it finishes, Pulumi prints the stack’s outputs, values it only knows once the resources exist. This program exports kubeconfig, the file kubectl needs to reach the new cluster, and nodePoolID. The kubeconfig is a secret, so Pulumi shows it as [secret] unless you ask for it with --show-secrets. Save it to a file and list the cluster’s nodes:

Terminal window
pulumi stack output kubeconfig --show-secrets > kubeconfig.yml
KUBECONFIG=./kubeconfig.yml kubectl get nodes

Customize the project#

The program reads the node pool’s size from nodePoolDesiredNodes. Raise it from 1 to 2:

Terminal window
pulumi config set nodePoolDesiredNodes 2

Deploy again. The preview shows the node pool as an update:

Terminal window
pulumi up

Then list the nodes again. A second node joins the pool:

Terminal window
KUBECONFIG=./kubeconfig.yml kubectl get nodes

The pool can grow to nodePoolMaxNodes, which defaults to 3.

To see what else you can add, browse the OVH provider in the Pulumi Registry.

Cleaning up#

Terminal window
pulumi destroy
pulumi stack rm

Related

The infrastructure platform for humans and agents.