Skip to main content

Search the Dev Center

Search tutorials, templates, examples, and more.

Load-balanced droplets on DigitalOcean

Basic example of load balanced droplets on DigitalOcean in Python

This example lives in the pulumi/examples repository. Check out just this directory to use it:

Get started with this example
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examples
git -C pulumi-examples sparse-checkout set digitalocean-py-loadbalanced-droplets
cd pulumi-examples/digitalocean-py-loadbalanced-droplets

Starting point for building a Pulumi sample architecture on DigitalOcean. This example provisions a set of load-balanced droplets behind a DigitalOcean load balancer, in Python.

Prerequisites#

  1. Install Pulumi
  2. Configure DigitalOcean credentials
  3. Install Python

Deploying the example#

  1. Create a new stack, which is an isolated deployment target for this example:

    Terminal window
    pulumi stack init dev
  2. Set your DigitalOcean personal access token:

    Terminal window
    pulumi config set --secret digitalocean:token YOURDIGITALOCEANTOKEN
  3. Create a Python virtualenv, activate it, and install dependencies:

    Terminal window
    python3 -m venv venv
    source venv/bin/activate
    pip install -r requirements.txt
  4. Run pulumi up to preview and deploy changes:

    Terminal window
    pulumi up
    Updating (dev):
    Type Name Status
    + pulumi:pulumi:Stack digitalocean-py-loadbalanced-droplets created
    + ├─ digitalocean:index:Tag demo-app created
    + ├─ digitalocean:index:Tag web-2 created
    + ├─ digitalocean:index:Tag web-0 created
    + ├─ digitalocean:index:Tag web-1 created
    + ├─ digitalocean:index:LoadBalancer public created
    + ├─ digitalocean:index:Droplet web-0 created
    + ├─ digitalocean:index:Droplet web-2 created
    + └─ digitalocean:index:Droplet web-1 created
    Outputs:
    endpoint: "138.197.62.183"
    Resources:
    + 9 created
    Duration: 3m2s
  5. Curl the HTTP server:

    Terminal window
    curl "$(pulumi stack output endpoint)"

Cleaning up#

Once you are done, you can destroy all of the resources, and the stack:

Terminal window
pulumi destroy
pulumi stack rm

Related

The infrastructure as code platform for any cloud.