---
title: "Quickstart: Run a job with a machine pool"
description: "Get a working machine pool and a job running against it in five steps using on-demand virtual machines."
---

# 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](/machine-pools/tutorial.md).

:::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](/machine-pools.md).
-   The following [permissions](/administration/organization/permissions.md):
    -   **Organization owner** for your Anyscale organization.
    -   **Cloud collaborator** or **cloud owner** for your Anyscale cloud.
-   An authenticated Anyscale CLI. See [CLI configuration](/reference/quickstart-cli.md).

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:

```bash
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:

```yaml
# 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](/machine-pools/config-ref.md).

Apply the configuration:

```bash
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`:

```python
# 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:

```yaml
# 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:

```bash
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:

```bash
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`:

```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:

```bash
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

-   [Tutorial: Create and use an Anyscale-managed machine pool](/machine-pools/tutorial.md) walks through capacity reservations, multi-partition pools, workspace eviction, and priority preemption.
-   [What is the global resource scheduler?](/machine-pools/global-resource-scheduler.md) explains scheduling rules, custom tag selectors, and preemption behavior.
-   [Monitor and observe machine pools in the Anyscale console](/machine-pools/console.md) covers the Anyscale console dashboards for monitoring pool utilization.

---

Previous: [Overview](/machine-pools.md) | Next: [Machine pools console](/machine-pools/console.md)