<br />

<br />

<br />

<br />

<br />

<br />

Traffic migration switches the request routing between the versions within a
service of your application, moving traffic from one or more versions to a
single new version.

Traffic is migrated immediately between your versions in the
flexible environment. Unlike versions in the standard environment,
[gradual traffic migration](https://docs.cloud.google.com/appengine/docs/standard/migrating-traffic)
is not supported in the flexible environment.

If you immediately migrate traffic to a new version without any running
instances then your app will have a spike in latency while instances are being
created. You can avoid a spike in latency by using the
[App Engine Admin API](https://docs.cloud.google.com/appengine/docs/admin-api) to provision
sufficient instances of the new app's version before you migrate traffic to it.

Set [`minTotalInstances`](https://docs.cloud.google.com/appengine/docs/admin-api/reference/rest/v1/apps.services.versions#automaticscaling)
for the new version to the number needed to handle expected traffic. After
migration is complete, you can reset this field so that autoscaling occurs
if traffic drops.

You can split traffic between versions of your app, increasing the amount of
traffic a version receives in stages.


For information about splitting traffic between two or more versions of your
app, see [Traffic Splitting](https://docs.cloud.google.com/appengine/docs/flexible/splitting-traffic).

## Before you begin

Before you can configure traffic to a version, ensure that your user account
includes the [required privileges](https://docs.cloud.google.com/appengine/docs/flexible/access-control#basic_roles).

## Migrating traffic to a new version

### Console

To migrate traffic in the Google Cloud console, go to the Versions page:

[Go to Versions](https://console.cloud.google.com/appengine/versions)

1. Select the version to which you want to migrate 100% of the traffic.
2. Click **Migrate traffic**.
3. Optional: When warmup requests are enabled your traffic is migrated gradually. To migrate traffic immediately, select the option under the **Show advanced options** section.

### gcloud

After installing the [Google Cloud CLI](https://docs.cloud.google.com/sdk/docs), you run the [`gcloud
app services set-traffic`](https://docs.cloud.google.com/sdk/gcloud/reference/app/services/set-traffic)
command to migrate 100% of traffic to a single version. For example:

- To migrate traffic immediately:

  ```bash
  gcloud app services set-traffic [MY_SERVICE] --splits [MY_VERSION]=1
  ```
- To gradually migrate traffic, you include the optional `--migrate` flag:

  ```bash
  gcloud app services set-traffic [MY_SERVICE] --splits [MY_VERSION]=1 --migrate
  ```

### API

To programmatically migrate traffic, you can use the Admin API,
see [Migrating and Splitting
Traffic](https://docs.cloud.google.com/appengine/docs/admin-api/migrating-splitting-traffic) for details.