Running App Engine Apps on Kubernetes Engine

This guide shows you how to run an App Engine flexible environment application on Kubernetes Engine. To run your app on Kubernetes Engine, you need to create a Dockerfile for it, build a container using that Dockerfile, and run the container in Kubernetes Engine. 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 Kubernetes Engine, Container Builder APIs.

    Enable the APIs

  4. These instructions assume you have already downloaded, installed, and initialized the Google Cloud SDK: if not,
    Download the SDK
  5. 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.
  6. Download and install git.

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 Kubernetes Engine:

    gcloud config set project [YOUR-PROJECT-ID]
    

    Replace [YOUR-PROJECT-ID] with your Kubernetes Engine project ID.

  3. Build the container using the following command:

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

    Replace [YOUR-PROJECT-ID] with the project ID of your Kubernetes Engine 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 [https://cloudbuild.googleapis.com/v1/projects/YOUR-PROJECT-ID/builds/xxxxxxx-xxxx-xxx-xxx-xxxxxxxxxxxx].
    Logs are permanently available at [https://console.developers.google.com/logs/viewer?resource=build&project=YOUR-PROJECT-ID&filters=text:xxxx-xxx-xxx-xxxxxxxxxxxx]].
    
    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  gcr.io/YOUR-PROJECT-ID/YOUR-CONTAINER-NAME  SUCCESS<
    

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

Running your app in Kubernetes Engine

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 Kubernetes Engine 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:

    kubectl run [YOUR-DEPLOYMENT-NAME] --image=gcr.io/[YOUR-PROJECT-ID]/[YOUR-CONTAINER-NAME] --port=8080
    

    Replace [YOUR-DEPLOYMENT-NAME] with the name you want to use for your deployment, replace [YOUR-PROJECT-ID] with your Kubernetes Engine 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 Kubernetes Engine:

    http://EXTERNAL-IP:8080
    

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

You've successfully deployed and run your App Engine Ruby app on Kubernetes Engine!

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.

Send feedback about...

App Engine flexible environment for Ruby docs