Pulumi

Pulumi is a infrastructure-as-code tool for managing infrastructure in one of several supported programming languages. Pulumi can be used to automatically provision, update and decomission your Symbiosis resources.

The Symbiosis provider supports Pulumi for Typescript/Javascript, C#, Go, Python and YAML.

Installing Pulumi

In order to install pulumi you need to both install the command line tool and also the packages necessary for your language of choice.

Lets start by installing the CLI:

brew install pulumi/tap/pulumi

Verify that the CLI was installed correctly:

pulumi version

Bootstrapping a Pulumi project

With the CLI installed we can proceed by creating a new project for our configuration files.

First, lets create the directory and change into it:

mkdir symbiosis-pulumi
cd symbiosis-pulumi

Next, lets use the CLI to scaffold a new project using our language of choice.

pulumi new typescript -y

Pulumi should now have populated the directory with the files necessary to run. However it will not contain any configuration.

Configuring a Symbiosis cluster

Now that we have the project ready we can proceed to define the resource that we want Pulumi to manage. So, next up we need to install the Symbiosis plugin:

# For NPM
npm install @symbiosis-cloud/symbiosis-pulumi
# ... or Yarn
yarn add @symbiosis-cloud/symbiosis-pulumi

With the plugin install we can proceed by opening the core entrypoint (depending on language, ie. index.ts for typescript). Replace with these lines in order to define a cluster and node pool.

import * as pulumi from "@pulumi/pulumi";
import * as symbiosis from "@symbiosis-cloud/symbiosis-pulumi";

const cluster = new symbiosis.Cluster("my-cluster", {
    region: "germany-1"
});

const nodePool = new symbiosis.NodePool("my-pool-1", {
    cluster: cluster.name,
    nodeType: "general-1",
    quantity: 3,
});

export const kubeconfig = cluster.kubeconfig;

These steps instruct Pulumi to allocate a new cluster named my-cluster and attach a node pool with 3 nodes of type general-1 and export the kubeconfig variable we will need to connect to the cluster later on. The API docs list all possible arguments that can be passed for both cluster and node pool, such as autoscaling configuration.

Next step is to configure our Symbiosis API Key, they can be generated from the API Keys tab in the UI, by API or by CLI.

pulumi config set symbiosis:apiKey MY_API_KEY

Provisioning the cluster

Now we're ready to deploy our cluster. Pulumi will generate a plan for how to achieve the desired state. As this is a first deploy Pulumi will only prompt for the creation of your new cluster and not modify or delete any existing resources. In order to proceed Pulumi will ask for your confirmation:

$ pulumi up
Previewing update (dev)

     Type                         Name              Plan
     pulumi:pulumi:Stack          symbiosis-pulumi
 +   ├─ symbiosis:index:Cluster   my-cluster        create
 +   └─ symbiosis:index:NodePool  my-pool-1         create


Outputs:
  + kubeconfig: output<string>

Resources:
    + 2 to create
    1 unchanged

Do you want to perform this update?
> yes
  no
  details

After the cluster is initialized we can use the output variable to export the kubeconfig necessary to access the cluster:

pulumi stack output kubeconfig --show-secrets >config

Verify that the config works properly:

$ KUBECONFIG=config kubectl get nodes

The config can be placed in ~/.kube/config to be automatically picked up by tools such as kubectl.

Next steps

Pulumi can also be used to provision your Kubernetes deployments, services or other resources. Have a look into their registry to identify which parts of your infrastructure can be provisioned in Pulumi.

Further reading: