Managed Service for Apache Spark clusters can be created on Compute Engine
[sole-tenant nodes](https://docs.cloud.google.com/compute/docs/nodes/sole-tenant-nodes.md.txt). A sole-tenant node
is a Compute Engine server that is dedicated to hosting your project's
VMs only. Creating a Managed Service for Apache Spark cluster on a sole tenant node
keeps the cluster's VMs physically separate from VMs in other projects. The
clusters function as standard Managed Service for Apache Spark clusters, but with
additional hardware isolation to address security and compliance concerns.

Managed Service for Apache Spark sole-tenant node clusters are created in a
user-specified *sole-tenant node group*. Each cluster's master, worker, and
secondary worker instances will be created within this sole-tenant node group.

> [!CAUTION]
> **Caution:** Managed Service for Apache Spark defaults to preemptible VMs for [secondary workers](https://docs.cloud.google.com/managed-spark/docs/concepts/compute/secondary-vms.md.txt), which are not supported by Compute Engine sole-tenant nodes. If you plan to use secondary workers with your sole-tenant cluster, by [manually
> adding them](https://docs.cloud.google.com/managed-spark/docs/concepts/compute/secondary-vms#using_secondary_workers) or using an [autoscaling policy](https://docs.cloud.google.com/managed-spark/docs/concepts/configuring-clusters/autoscaling.md.txt#gcloud-command) that scales up secondary workers, you must set your secondary worker type to non-preemptible.

## First steps

1. See [Before you begin](https://docs.cloud.google.com/compute/docs/nodes/provisioning-sole-tenant-vms.md.txt#before-you-begin).

2. [Create a sole-tenant node template](https://docs.cloud.google.com/compute/docs/nodes/provisioning-sole-tenant-vms.md.txt#creating_a_sole-tenant_node_template).

3. [Create a sole-tenant node group](https://docs.cloud.google.com/compute/docs/nodes/provisioning-sole-tenant-vms.md.txt#creating_a_soletenant_node_group).

   - Use [autoscaling node groups](https://docs.cloud.google.com/compute/docs/nodes/autoscaling-node-groups.md.txt)
     if you will create [autoscaling clusters](https://docs.cloud.google.com/managed-spark/docs/concepts/configuring-clusters/autoscaling.md.txt)
     in the sole-tenant node group.

     **Node group autoscaling recommendations:**
     - Make sure the node group's `max-nodes` is sufficient for the `maxInstances` of clusters you will create in the sole-tenant node group.
     - Use the default or `migrate-within-node-group` node group maintenance policy; VMs may be unavailable for up to one hour with the `restart-in-place` policy.

## Creating a sole-tenant cluster

- Before creating a sole-tenant cluster, see the
  [sole-tenant node VM restrictions](https://docs.cloud.google.com/compute/docs/nodes/sole-tenant-nodes.md.txt#restrictions).

- If you create an
  [autoscaling cluster](https://docs.cloud.google.com/managed-spark/docs/concepts/configuring-clusters/autoscaling.md.txt)
  in a sole-tenant node group, it is recommended that
  [node group also use autoscaling](https://docs.cloud.google.com/compute/docs/nodes/autoscaling-node-groups.md.txt)
  (see [Node group autoscaling recommendations](https://docs.cloud.google.com/managed-spark/docs/concepts/configuring-clusters/sole-tenant-nodes.md.txt#node-autoscaling-recommendations)).

### gcloud Command

To create a sole-tenant cluster, pass the `--node-group` flag to the
[gcloud dataproc clusters create](https://docs.cloud.google.com/sdk/gcloud/reference/dataproc/clusters/create.md.txt)
command.

Flag notes:

- `--region` (required): Must match the region of the sole-tenant-group.
- `--node-group` (required): You can specify the sole tenant node group name ("node-group-name") or the sole-tenant node group resource URI ("projects/<var translate="no">project-id</var>/zones/<var translate="no">zone</var>/nodeGroups/<var translate="no">node-group-name</var>").
- `--zone` (required): The cluster zone must match the sole-tenant node group zone.

```
gcloud dataproc clusters create cluster-name \
    --region=region \
    --zone=zone \
    --node-group=node group resource name or URI \
    ... other args
  
```

### REST API

Create a sole-tenant cluster using a
[clusters.create](https://docs.cloud.google.com/managed-spark/docs/reference/rest/v1/projects.regions.clusters/create.md.txt)
request that specifies the
[NodeGroupAffinity.nodeGroupUri](https://docs.cloud.google.com/managed-spark/docs/reference/rest/v1/ClusterConfig.md.txt#NodeGroupAffinity)
of the sole-tenant node group.

Note: the cluster zone specified in the [`zoneUri`](https://docs.cloud.google.com/managed-spark/docs/reference/rest/v1/ClusterConfig.md.txt#GceClusterConfig.FIELDS.zone_uri)
field must match the sole-tenant node group zone.

> [!NOTE]
> An easy way to examine and construct the JSON body of a Managed Service for Apache Spark API clusters request is to open the Managed Service for Apache Spark [Create a cluster](https://console.cloud.google.com/dataproc/clusters/create) Google Cloud console page, fill in the applicable fields on the page, then click the **Equivalent REST** button at the bottom of the left panel to view the POST request with the completed JSON request body.

### Console

Currently, creating a sole-tenant Managed Service for Apache Spark cluster is
not supported in the Google Cloud console.