If you run Pulumi for the first time, you will be asked to log in. Follow the instructions on the screen to login. You may need to create an account first, don't worry it is free. Or you handle the state of the different stacks yourself, and use
pulumi login --local
pulumi new civo-javascript --name pulumi-civo-workshop --dir pulumi-civo-workshop
Wizard will ask you for the description of the project, and the stack name. You can leave the default values.
At the end the wizard will ask you to configure the project. You can skip this step by pressing Enter
key.
civo:token: The token that allows you access your CIVO account:
Saved config
Now open the index.js
file and replace/argument the content with the following code:
"use strict";
const pulumi = require("@pulumi/pulumi");
const civo = require("@pulumi/civo");
const firewall = new civo.Firewall("civo-firewall", {
name: "my-civo-firewall",
region: "PHX1",
createDefaultRules: true
})
const cluster = new civo.KubernetesCluster("civo-k3s-cluster", {
name: "my-civo-k3s-cluster",
pools: {
nodeCount: 3,
size: "g4s.kube.medium"
},
region: "PHX1",
firewallId: firewall.id,
applications: "cert-manager,rancher,metrics-server,traefik2-nodeport"
})
exports.clusterName = cluster.name
exports.kubeconfig = pulumi.secret(cluster.kubeconfig)
pulumi up
This command will show you a preview of all the resources and asks you if you want to deploy them. You can run dedicated commands to see the preview or to deploy the resources.
pulumi preview
# or
pulumi up
Pulumi Stacks are a great way to manage different environments and configurations.
To create a new stack, execute the following command.
pulumi stack init prod
This will create a new stack called prod
. You can see all the available stacks with the following command.
pulumi stack ls
To destroy the stack, run the following command.
pulumi destroy
pulumi stack rm <stack-name>