Jump toUpdate content
Deploying Your First Scaleway Kubernetes Kapsule using Pulumi
- compute
- Pulumi
- Scaleway-infrastructures
- cloud
- Kubernetes
- Pulumi
Pulumi is an open-source infrastructure-as-code tool for creating, deploying and managing cloud infrastructure. Pulumi works with traditional infrastructures like VMs, networks, and databases and modern architectures, including containers, Kubernetes clusters, and serverless functions. Pulumi supports dozens of public, private, and hybrid cloud service providers.
- You have an account and are logged into the Scaleway console
- You have created your API key
Installing Pulumi
Before you can deploy a Scaleway Kubernetes Kapsule, you need to install the Pulumi CLI. This can be done either on your local development machine or on your build agent. We cover the installation of the cli for some scenarios in the next section.
Pulumi stores metadata about your infrastructure so that it can manage your cloud resources. This metadata is called state.
Pulumi stores state in a backend of your choosing and there are two classes of backends:
- Service: a managed cloud experience using the online or self-hosted Pulumi Service application
- Self-Managed: a manually managed object store, including Scaleway Object Storage, AWS S3, Azure Blob Storage, Google Cloud Storage, any AWS S3 compatible server such as Minio or Ceph, or your local filesystem
Installation on MacOS
You can install Pulumi through the Homebrew package manager and using the official Pulumi Homebrew Tap. Open a terminal and type the following command:
$ brew install pulumi/tap/pulumi
Installation on Windows
You can install Pulumi using elevated permissions through the Chocolatey package manager:
$ choco install pulumi
Installation on Linux
To install, run the installation script via the following command:
$curl -fsSL https://get.pulumi.com | sh
This will install the pulumi CLI to ~/.pulumi/bin
and add it to your path. If this command fails at automatically adding pulumi to your path, you will be prompted to add it manually.
Alternatively, you can install Pulumi manually. Pulumi provided a prebuilt binary for Linux.
Head over to the available versions page to choose the version of Pulumi you want to install.
Extract the tarball and move the binaries in the pulumi directory to a directory included in your system’s $PATH
.
Verifying your Installation
To verify that you have successfully installed Pulumi, run the following command:
$ pulumi version
v3.36.0
Deploying your first Scaleway Kubernetes Kapsule using Pulumi
Now that you have installed Pulumi, you can start deploying your Scaleway Kubernetes Kapsule. Before you can create your first Pulumi program, you need to know what language you are going to use.
Pulumi is a multi-language infrastructure as code tool. You have a wide range of programming languages available and you can use the one you are the most comfortable with. Currently, (6/2022) Pulumi supports the following languages:
- Node.js (JavaScript / TypeScript)
- Python
- Go
- Java
- .NET (C#, VB, F#)
- YAML
In this tutorial, we will use Typescript.
Create a project folder (for example
scaleway-pulumi
) and navigate into the newly created directory:$ mkdir scaleway-pulumi && cd scaleway-pulumi
Create a new Pulumi program with the following command:
pulumi new typescript
This command will walk you through creating a new Pulumi project.
Enter a value or leave blank to accept the (default), and press <ENTER>.
Press ^C at any time to quit.
project name: pulumi-scaleway-quickstart
project description: (A minimal TypeScript Pulumi program)
Created project 'pulumi-scaleway-quickstart'
Please enter your desired stack name.
To create a stack in an organization, use the format <org-name>/<stack-name> (e.g. `acmecorp/dev`).
stack name: (dev)
Created stack 'dev'
Installing dependencies...
added 96 packages, and audited 97 packages in 6s
37 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
npm notice
npm notice New minor version of npm available! 8.13.2 -> 8.15.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.15.0
npm notice Run npm install -g npm@8.15.0 to update!
npm notice
Finished installing dependencies
Your new project is ready to go! ✨
To perform an initial deployment, run 'pulumi up'The argument
typescript
will tell Pulumi to create a new program in the using thetypescript
template.Pulumi offers plenty of templates, if you are unsure of what to use, just use type following command and choose from the huge collection of templates:
$ pulumi new
Please choose a template: [Use arrows to move, enter to select, type to filter]
aws-csharp A minimal AWS C# Pulumi program
aws-go A minimal AWS Go Pulumi program
aws-javascript A minimal AWS JavaScript Pulumi program
aws-python A minimal AWS Python Pulumi program
aws-typescript A minimal AWS TypeScript Pulumi program
azure-csharp A minimal Azure Native C# Pulumi program
azure-go A minimal Azure Native Go Pulumi program
azure-javascript A minimal JavaScript Pulumi program with the native Azure provider
azure-python A minimal Azure Native Python Pulumi program
....Add the Scaleway provider
The Scaleway provider binary is a third party binary. It can be installed using the pulumi plugin command.
$ pulumi plugin install resource scaleway v0.3.0 --server https://dl.briggs.work/pulumi/releases/plugins
Add the Scaleway provider to your project via the
npm
command:$ npm install @jaxxstorm/pulumi-scaleway@0.3.0 --save --save-exact
Set the Scaleway credentials
Add the Scaleway Credentials with the following commands to the Pulumi config:
$ pulumi config set scaleway:access_key YYYY --secret
$ pulumi config set scaleway:secret_key ZZZZ --secret
$ pulumi config set scaleway:project_id ZZZZAlternatively, you can set the API credentials via the environment variables:
$ export SCW_ACCESS_KEY=YYYY
$ export SCW_SECRET_KEY=ZZZZ
$ export SCW_PROJECT_ID=ZZZZAdd this code to your
index.ts
file:import * as pulumi from "@pulumi/pulumi";
import * as scaleway from "@jaxxstorm/pulumi-scaleway";
const kapsule = new scaleway.KubernetesCluster("pulumi-kapsule", {
name: "pulumi-kapsule",
version: "1.23",
region: "fr-par",
cni: "cilium",
tags: [
"pulumi",
"scaleway",
],
autoUpgrade: {
enable: true,
maintenanceWindowStartHour: 3,
maintenanceWindowDay: "monday"
},
admissionPlugins: [
"AlwaysPullImages",
],
}
)
new scaleway.KubernetesNodePool("pulumi-kapsule-pool", {
zone: "fr-par-1",
name: "pulumi-kapsule-pool",
nodeType: "DEV1-L",
size: 1,
autoscaling: true,
minSize: 1,
maxSize: 3,
autohealing: true,
clusterId: kapsule.id,
})
export const kapsuleId = kapsule.id;
export const kubeconfig = pulumi.secret(kapsule.kubeconfigs[0].configFile);Run the following command to deploy your program:
$ pulumi up
The output of the preview command displays. The preview shows you the changes that will be made to your cloud infrastructure. You can then decide to deploy the changes or to cancel the deployment.
With the command
pulumi preview
, you explicitly ask Pulumi to preview the changes.$ pulumi up
Previewing update (dev)
View Live: https://app.pulumi.com/dirien/pulumi-scaleway-quickstart/dev/previews/216875e4-018c-4044-8586-7cda86d2ef63
Type Name Plan
+ pulumi:pulumi:Stack pulumi-scaleway-quickstart-dev create
+ ├─ scaleway:index:KubernetesCluster pulumi-kapsule create
+ └─ scaleway:index:KubernetesNodePool pulumi-kapsule-pool create
Outputs:
kapsuleId : output<string>
kubeconfig: output<string>
Resources:
+ 3 to create
Do you want to perform this update? [Use arrows to move, enter to select, type to filter]
yes
> no
detailsSelect “yes” to perform the update.
Tip:- You can skip the preview by using the flag
--skip-preview
or-f
- You can skip the confirmation dialog by using
--yes
or-y
Both flags are useful, when you run Pulumi in a CI environment.
The update process will take a few minutes, and you should see the following output when the update is done:
Do you want to perform this update? yes
Updating (dev)
View Live: https://app.pulumi.com/dirien/pulumi-scaleway-quickstart/dev/updates/2
Type Name Status
pulumi:pulumi:Stack pulumi-scaleway-quickstart-dev
+ ├─ scaleway:index:KubernetesCluster pulumi-kapsule created
+ └─ scaleway:index:KubernetesNodePool pulumi-kapsule-pool created
Outputs:
+ kapsuleId : "fr-par/<id>"
+ kubeconfig: [secret]
Resources:
+ 2 created
1 unchanged
Duration: 5m20s- You can skip the preview by using the flag
Retrieve the kubeconfig file
In our
typescript
code, we exported the kubeconfig file as an output and marked it as a secret.$ export const kubeconfig = pulumi.secret(kapsule.kubeconfigs[0].configFile);
To retrieve the kubeconfig file for manual use, you can use the following command:
$ pulumi stack output kubeconfig --show-secrets > kubeconfig.yaml
Run the following command to verify that the kubeconfig file is valid.
$ export KUBECONFIG=kubeconfig.yaml && kubectl get nodes
NAME STATUS ROLES AGE VERSION
scw-pulumi-kapsule-pulumi-kapsule-pool-6d0c822 Ready <none> 25m v1.23.6
Add new resources to your Pulumi program
This section shows you how to modify your existing Pulumi program to add a new worker pool to your cluster.
Add this line to your existing index.ts
file:
new scaleway.KubernetesNodePool("pulumi-kapsule-pool-small", {
zone: "fr-par-1",
name: "pulumi-kapsule-pool-small",
nodeType: "DEV1-M",
size: 2,
autoscaling: false,
autohealing: true,
clusterId: kapsule.id,
})
Run the pulumi preview
command to see the potential changes in your cloud infrastructure.
$ pulumi preview
Previewing update (dev)
View Live: https://app.pulumi.com/dirien/pulumi-scaleway-quickstart/dev/previews/65fcf170-42b8-4d29-85b6-91515b222a64
Type Name Plan
pulumi:pulumi:Stack pulumi-scaleway-quickstart-dev
+ └─ scaleway:index:KubernetesNodePool pulumi-kapsule-pool-small create
Resources:
+ 1 to create
3 unchanged
The +
sign indicates that you are adding a new resource to your infrastructure.
~
indicates that a resource will be modified.-
indicates that a resource will be deleted.
You can deploy the changes you have made. Use the -y
and -f
flags to skip the confirmation dialog and the preview.
$ pulumi up -y -f
Updating (dev)
View Live: https://app.pulumi.com/dirien/pulumi-scaleway-quickstart/dev/updates/4
Type Name Status
pulumi:pulumi:Stack pulumi-scaleway-quickstart-dev
+ └─ scaleway:index:KubernetesNodePool pulumi-kapsule-pool-small created
Outputs:
kapsuleId : "fr-par/<id>"
kubeconfig: [secret]
Resources:
+ 1 created
3 unchanged
Duration: 3m40s
After a couple of minutes, everything should be deployed, and you can test your new worker pool.
$ export KUBECONFIG=kubeconfig.yaml && kubectl get nodes
NAME STATUS ROLES AGE VERSION
scw-pulumi-kapsu-pulumi-kapsule-pool-sm-059c03 Ready <none> 3m56s v1.23.6
scw-pulumi-kapsu-pulumi-kapsule-pool-sm-905ac2 Ready <none> 4m18s v1.23.6
scw-pulumi-kapsule-pulumi-kapsule-pool-6d0c822 Ready <none> 76m v1.23.6
Deleting your infrastructure
You can delete your deployment using the pulumi destroy
command. The preview of the deletion displays. You are then asked to confirm the deletion.
$ pulumi destroy
Previewing destroy (dev)
View Live: https://app.pulumi.com/dirien/pulumi-scaleway-quickstart/dev/previews/9a822c2d-718b-4818-b7c4-d598df6c18e8
Type Name Plan
- pulumi:pulumi:Stack pulumi-scaleway-quickstart-dev delete
- ├─ scaleway:index:KubernetesNodePool pulumi-kapsule-pool delete
- ├─ scaleway:index:KubernetesNodePool pulumi-kapsule-pool-small delete
- └─ scaleway:index:KubernetesCluster pulumi-kapsule delete
Outputs:
- kapsuleId : "fr-par/<id>"
- kubeconfig: [secret]
Resources:
- 4 to delete
Do you want to perform this destroy? [Use arrows to move, enter to select, type to filter]
yes
> no
details
Confirm the deletion or if initiated accidentally, you can cancel the deletion. Keep in mind that you can use the flags for skipping the confirmation dialog and the preview (-y
and -f
).
$ pulumi destroy
Previewing destroy (dev)
View Live: https://app.pulumi.com/dirien/pulumi-scaleway-quickstart/dev/previews/9a822c2d-718b-4818-b7c4-d598df6c18e8
Type Name Plan
- pulumi:pulumi:Stack pulumi-scaleway-quickstart-dev delete
- ├─ scaleway:index:KubernetesNodePool pulumi-kapsule-pool delete
- ├─ scaleway:index:KubernetesNodePool pulumi-kapsule-pool-small delete
- └─ scaleway:index:KubernetesCluster pulumi-kapsule delete
Outputs:
- kapsuleId : "fr-par/<id>"
- kubeconfig: [secret]
Resources:
- 4 to delete
Do you want to perform this destroy? yes
Destroying (dev)
View Live: https://app.pulumi.com/dirien/pulumi-scaleway-quickstart/dev/updates/5
Type Name Status
- pulumi:pulumi:Stack pulumi-scaleway-quickstart-dev deleted
- ├─ scaleway:index:KubernetesNodePool pulumi-kapsule-pool deleted
- ├─ scaleway:index:KubernetesNodePool pulumi-kapsule-pool-small deleted
- └─ scaleway:index:KubernetesCluster pulumi-kapsule deleted
Outputs:
- kapsuleId : "fr-par/<id>"
- kubeconfig: [secret]
Resources:
- 4 deleted
Duration: 59s
The resources in the stack have been deleted, but the history and configuration associated with the stack are still maintained.
If you want to remove the stack completely, run 'pulumi stack rm dev'.
You got a first impression on the lifecycle of an infrastructure using Pulumi. There are many more aspects to discover. Check the official Pulumi documentation to find out more.