Skip to main content

Quickstart: Run a job with a machine pool

Quickstart: Run a job with a machine pool

This quickstart walks through creating a small Anyscale-managed machine pool, running a job against it, and tearing it down. Use this guide to confirm your setup before adopting machine pools for capacity reservations or shared compute. For a complete tutorial that covers capacity reservations, partitions, workspace eviction, and priority preemption, see Tutorial: Create and use an Anyscale-managed machine pool.

info

Machine pools and the global resource scheduler are in beta release.

Requirements

  • An Anyscale organization with at least one VM-based or Amazon EKS or Google GKE Anyscale cloud. Anyscale doesn't support machine pools on Azure, AKS, or other Kubernetes distributions. See Share compute resources with Anyscale machine pools.
  • The following permissions:
    • Organization owner for your Anyscale organization.
    • Cloud collaborator or cloud owner for your Anyscale cloud.
  • An authenticated Anyscale CLI. See CLI configuration.

This quickstart provisions an on-demand virtual machine. Anyscale recommends completing the cleanup step in the same session to avoid leaving instances running.

Step 1: Create and attach a machine pool

Create an empty pool and attach it to your Anyscale cloud. Replace <cloud-name> with the name of your cloud:

anyscale machine-pool create --name quickstart-pool
anyscale machine-pool attach --name quickstart-pool --cloud <cloud-name>

Step 2: Configure the pool

Save the following to quickstart-pool.yaml. This config defines a single on-demand m5.2xlarge instance available to any workload type:

# quickstart-pool.yaml
kind: ANYSCALE_MANAGED
machine_types:
- machine_type: quickstart-cpu
launch_templates:
- instance_type: m5.2xlarge
market_type: ON_DEMAND
partitions:
- name: default
size: 1
rules:
- selector: workload-type
priority: 100

The workload-type selector matches any Anyscale workload, so jobs, services, and workspaces all schedule into this pool. See Machine pool configuration file reference.

Apply the configuration:

anyscale machine-pool update --name quickstart-pool --spec-file quickstart-pool.yaml
note

For Google Cloud, replace m5.2xlarge with a comparable Google Cloud instance type.

Step 3: Submit a job

Save the following to main.py:

# main.py
import ray

ray.init()
print("Cluster resources:", ray.cluster_resources())

Save the following to quickstart-job.yaml. Replace <cloud-name> with the name of your Anyscale cloud:

# quickstart-job.yaml
name: quickstart-job
cloud: <cloud-name>
entrypoint: python main.py
max_retries: 0
compute_config:
head_node:
instance_type: m5.2xlarge
worker_nodes:
- instance_type: quickstart-cpu
min_nodes: 1
max_nodes: 1
flags:
cloud_deployment:
machine_pool: quickstart-pool

The instance_type: quickstart-cpu field on the worker matches the machine_type name from your pool spec, and the cloud_deployment.machine_pool flag routes the worker to your pool. The head node uses an on-demand instance from your cloud, not the pool.

Submit the job:

anyscale job submit -f quickstart-job.yaml --working-dir=.

The pool starts the worker. The job prints the cluster resources and exits.

To inspect the pool state during the run, use the following command:

anyscale machine-pool describe --name quickstart-pool

Step 4: Tear down the pool

Scale the pool to zero, detach it from your cloud, and delete it.

Save the following to quickstart-cleanup.yaml:

# quickstart-cleanup.yaml
kind: ANYSCALE_MANAGED
machine_types: []

Apply the cleanup spec, detach the pool, then delete it. Replace <cloud-name> with the name of your Anyscale cloud:

anyscale machine-pool update --name quickstart-pool --spec-file quickstart-cleanup.yaml
anyscale machine-pool detach --name quickstart-pool --cloud <cloud-name>
anyscale machine-pool delete --name quickstart-pool

Next steps