1. Deploy JupyterHub for AI Training on Droplets.


    To deploy JupyterHub for AI training on DigitalOcean Droplets using Pulumi, you need to create the infrastructure that consists of the Droplets (virtual machines) where the JupyterHub will run. You will also need a mechanism to execute a startup script that sets up JupyterHub on your Droplet after it's created.

    Here's a Pulumi Python program that demonstrates how to create a DigitalOcean Droplet and run a startup script to install JupyterHub:

    import pulumi import pulumi_digitalocean as digitalocean # Configuration for the Droplet droplet_name = 'ai-training-droplet' region = 'nyc3' # New York 3 datacenter size = 's-2vcpu-4gb' # Standard Droplet with 2 vCPUs and 4GB RAM image = 'docker-20-04' # Slug for a Docker pre-installed image # User data (startup script) to install and setup JupyterHub user_data = '''#!/bin/bash apt-get update apt-get -y install python3 python3-pip pip3 install jupyterhub notebook # Create a JupyterHub user - you can replace 'jupyterhub_user' with your desired user name useradd -m jupyterhub_user echo jupyterhub_user:password | chpasswd # Run JupyterHub on startup nohup jupyterhub --port 80 & ''' # Create a new SSH key to use with the Droplet ssh_key = digitalocean.SshKey("example_ssh_key", name="example_ssh_key", public_key="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC...") # Instantiate a Droplet droplet = digitalocean.Droplet(droplet_name, region=region, size=size, image=image, user_data=user_data, ssh_keys=[ssh_key.id], tags=["jupyterhub", "training"]) # Export the Droplet's IP address pulumi.export('droplet_ip', droplet.ipv4_address)

    In the above code:

    • We import the pulumi and pulumi_digitalocean modules to interact with Pulumi and DigitalOcean respectively.
    • We define configurations for our Droplet such as the name, region, size, image, and a startup script user_data. The startup script is executed when the Droplet is created, installing Python, JupyterHub, and creating a JupyterHub user account.
    • An SSH key is created for secure access to the Droplet.
    • The DigitalOcean Droplet is provisioned with the specified configurations. We attach the SSH key and assign it tags for organization.
    • Lastly, we export the IP address of the Droplet so that it can be accessed once it's ready.

    To run this program:

    1. Ensure you have Pulumi installed and configured with DigitalOcean.
    2. Save the above code in a file named __main__.py.
    3. Run pulumi up in the same directory to create the cloud resources.

    Remember to secure your JupyterHub installation properly by setting up a more secure authentication method and HTTPS before using it for sensitive workloads. This example uses a basic setup that should not be used as-is for a production environment.