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:
Verify that your application deploys and runs successfully in App Engine flexible environment.
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.
Enable the Kubernetes Engine, Container Builder APIs.
- These instructions assume you have already downloaded, installed, and
initialized the Google Cloud SDK: if not,
Download the SDK
- Download and install git.
Creating a Dockerfile for your App Engine app
To create a Dockerfile for your app:
- Make sure you have compiled and fully built your application, for example, if you use Maven, by running the command
- Change to the directory of the fully built application, typically
- Build a Dockerfile for your app by running the following command:
gcloud beta app gen-config --customWhen you are prompted to change the runtime field in the
app.yamlto custom, select Y to confirm.
Building a container from the Dockerfile
To build a container:
Make sure you are in the App Engine application directory that contains the Dockerfile.
Change the default project used by the
gcloudtool so it points to the project you are using to run your app in Kubernetes Engine:
gcloud config set project [YOUR-PROJECT-ID]
[YOUR-PROJECT-ID]with your Kubernetes Engine project ID.
Build the container using the following command:
gcloud container builds submit --tag gcr.io/[YOUR-PROJECT-ID]/[YOUR-CONTAINER-NAME] .
[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.
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:
Create the cluster (this may take a few minutes):
gcloud container clusters create [YOUR-CLUSTER-NAME]
[YOUR-CLUSTER-NAME]with the name you want to give the cluster.
From the command line, set your compute zone:
gcloud config set compute/zone us-central1-b
Make sure the Kubernetes Engine
kubectltool is authorized:
gcloud container clusters get-credentials [YOUR-CLUSTER-NAME]
Follow the prompts to authorize the tool.
Run the container that holds your app:
kubectl run [YOUR-DEPLOYMENT-NAME] --image=gcr.io/[YOUR-PROJECT-ID]/[YOUR-CONTAINER-NAME] --port=8080
[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.
Expose the container for public access:
kubectl expose deployment [YOUR-DEPLOYMENT-NAME] --type="LoadBalancer"
[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.
View the external IP address for your app:
kubectl get service [YOUR-DEPLOYMENT-NAME]
[YOUR-DEPLOYMENT-NAME]with the name you used in the previous steps. If the
EXTERNAL IPfield is empty, wait for awhile, then re-invoke the command.
View the app running in Kubernetes Engine:
EXTERNAL-IPwith the external IP address you obtained in the previous step.
You've successfully deployed and run your App Engine Java app on Kubernetes Engine!
You may want to learn more about Kubernetes and the
Kubernetes Engine uses Kubernetes for container management, deployment and
scaling. More information on Kubernetes is available on the external
This guide uses
kubectl, the command line interface for managing
Kubernetes clusters. More information on
kubectl is available in the