Overview
Pod
provides a way to run arbitrary code on Beam. It’s an abstraction that lets you deploy a serverless container as a service, without the need to use Beam’s traditional Pythonic syntax.
This is especially useful when you want to bring your own container image or host generic webservers on Beam.
Running Arbitrary Code
You can run arbitrary code inline by specifying a container image, environment variables, and entry point directly from the command line.
For example, the following command spins up a Jupyter notebook server on Beam:
When you run this command, Beam will build the container image, sync the files, and start the container. It will then print the URL of the notebook server to the console.
Exposing Ports
You can expose ports to the outside world by specifying the ports you want to expose in the ports
parameter.
ports
accepts a list, so you can expose multiple ports too.
Specifying Entry Points
An entry point is the command or script that the container runs when it starts. In Beam, you can interact with Pods using the CLI or the Python SDK.
CLI
Use the --entrypoint
flag with the beam run
command.
Python SDK
Use the entrypoint parameter in your Pod definition.
Passing Environment Variables
You can pass environment variables into your container for credentials or other parameters. Like entry points, environment variables can be defined in both the CLI or the Python SDK:
CLI
Use the --env
flag with beam run
.
Python SDK
Use the env
parameter in your Pod definition.
Summary
Using Pod on Beam:
- Allows you to run arbitrary code in a serverless container.
- Supports both CLI (through beam run) and the Python SDK (through Pod objects).
- Makes it easy to specify entry points and environment variables to configure your workload.
- Provides logs and a unique URL so you can access your running service (like a Jupyter notebook).
Here’s an end-to-end example of how to run a Jupyter notebook server on Beam using the Python SDK:
You can run this command directly as a Python script.
Running this command will print the URL of the notebook server to the console.
Was this page helpful?