Running App Engine Apps on GKE

This guide shows you how to run an App Engine flexible environment application on GKE. To run your app on GKE, you need to create a Dockerfile for it, build a container using that Dockerfile, and run the container in GKE. No code changes are required.

Before you begin

Before following the instructions on this page, take the following steps:

  1. Verify that your application deploys and runs successfully in App Engine flexible environment.

  2. In these instructions, you'll use the same project that you used for your App Engine app. You can always create and use a new project, if you want.

  3. Enable the GKE, Cloud Build APIs.

    Enable the APIs

  4. Download and install the Google Cloud SDK and then initialize the gcloud tool:
    Download the SDK

  5. Download and install the Kubernetes kubectl tool.

  6. Alternatively, you can use Google Cloud Shell, which comes with git and Cloud SDK already installed, and many other features, such as language support and code editors.

  7. Download and install git.

  8. Download and install Node.js and NPM. NPM (Node Package Manager) is usually installed alongside Node.js, but you can install the Yarn Package Manager as an alternative and use Yarn throughout the tutorial if you want. Important: For the best experience on Windows, upgrade to the latest version of Node.js package manager (npm) by running npm install -g npm. The latest npm installs dependencies in a flat directory structure, so installations are unlikely to conflict with the Windows maximum path length of 255 characters. If you prefer to keep using an older version of npm, you can reduce the length of paths by moving your project to the root of your drive, for example, C:\.

Creating a Dockerfile for your App Engine app

To create a Dockerfile for your app:

  1. Change to the application main directory.
  2. Build a Dockerfile for your app by running the following command:
    gcloud beta app gen-config --custom
    When you are prompted to change the runtime field in the app.yaml to custom, select Y to confirm.

Building a container from the Dockerfile

To build a container:

  1. Make sure you are in the App Engine application directory that contains the Dockerfile.

  2. Change the default project used by the gcloud tool so it points to the project you are using to run your app in GKE:

    gcloud config set project [YOUR-PROJECT-ID]

    Replace [YOUR-PROJECT-ID] with your GKE project ID.

  3. Build the container using the following command:

    gcloud builds submit --tag[YOUR-PROJECT-ID]/[YOUR-CONTAINER-NAME] .

    Replace [YOUR-PROJECT-ID] with the project ID of your GKE project, and replace [YOUR-CONTAINER-NAME] with the name of the container you want to use for your app container.

  4. Wait for the container to build: it may take awhile. When it finishes successfully, it shows a message like this one:

    Created [].
    Logs are permanently available at []].
    ID  CREATE_TIME DURATION  SOURCE                                                     IMAGES                               STATUS
    xxxxxxx-xxxx-xxx-xxx-xxxxxxxxxxxx  2017-03-04T00:42:10+00:00  1M32S     gs://YOUR-PROJECT-ID_cloudbuild/source/xxxxxxx.08.tgz  SUCCESS<

    Note the container name: you need to specify this when you run it in GKE.

Running your app in GKE

To run the container that holds your application:

  1. Create the cluster (this may take a few minutes):

    gcloud container clusters create [YOUR-CLUSTER-NAME]

    Replace [YOUR-CLUSTER-NAME] with the name you want to give the cluster.

  2. From the command line, set your compute zone:

    gcloud config set compute/zone us-central1-b
  3. Make sure the GKE kubectl tool is authorized:

    gcloud container clusters get-credentials [YOUR-CLUSTER-NAME]

    Follow the prompts to authorize the tool.

  4. Run the container that holds your app:


    Replace [YOUR-DEPLOYMENT-NAME] with the name you want to use for your deployment, replace [YOUR-PROJECT-ID] with your GKE project ID, and replace [YOUR-CONTAINER-NAME] with the name of the container you created for your app.

  5. Expose the container for public access:

    kubectl expose deployment [YOUR-DEPLOYMENT-NAME] --type="LoadBalancer"

    Replace [YOUR-DEPLOYMENT-NAME] with the name you used in the previous steps. You may need to wait several minutes before the external IP is viewable.

  6. View the external IP address for your app:

    kubectl get service [YOUR-DEPLOYMENT-NAME]

    Replace [YOUR-DEPLOYMENT-NAME] with the name you used in the previous steps. If the EXTERNAL IP field is empty, wait for awhile, then re-invoke the command.

  7. View the app running in GKE:


    Replace EXTERNAL-IP with the external IP address you obtained in the previous step.

You've successfully deployed and run your App Engine Node.js app on GKE!

What's next

You may want to learn more about Kubernetes and the kubectl command. Google Kubernetes Engine uses Kubernetes for container management, deployment and scaling. More information on Kubernetes is available on the external Kubernetes site.

This guide uses kubectl, the command line interface for managing Kubernetes clusters. More information on kubectl is available in the kubectl reference.