Quickstart for Google Container Engine

This quickstart shows you how to use Google Cloud Shell to deploy a prebuilt Docker container image with a simple Node.js example app.

Before you begin

Take the following steps to enable the Google Container Engine API:
  1. Visit the Container Engine page in the Google Cloud Platform Console.
  2. Create or select a project.
  3. Wait for the API and related services to be enabled. This can take several minutes
  4. Enable billing for your project.

    Enable billing

Use Google Cloud Shell

To interact with kubectl immediately, use the Google Cloud Shell, which comes preinstalled with the gcloud and kubectl command-line tools. Follow these steps to launch the Google Cloud Shell:

  1. Go to Google Cloud Platform Console.
  2. Click the Activate Google Cloud Shell button at the top of the console window.

    Google Cloud Platform console

    A Cloud Shell session opens inside a new frame at the bottom of the console and displays a command-line prompt.

    Cloud Shell session

Set defaults for the gcloud command-line tool

  1. Set a default Compute Engine zone. The following command sets the default zone as us-central1-b:

    gcloud config set compute/zone us-central1-b
    


You can view your defaults in the gcloud command-line tool by running the following command:

gcloud config list

Run a container image

Follow these steps to create a cluster, then run a simple Node.js "Hello Node" example app using the prebuilt container image at Google Container Registry. If you'd like to see the source code for this example app, see Hello Node code review.

  1. Create a cluster (this step can take a few minutes to complete).

    gcloud container clusters create example-cluster
    
  2. Ensure kubectl has authentication credentials:

    gcloud auth application-default login
    
  3. Run the container:

    kubectl run hello-node --image=gcr.io/google-samples/node-hello:1.0 --port=8080
    
  4. Expose the container. Note that the type="LoadBalancer option in kubectl requests that Google Cloud Platform provision a load balancer for your container, which is billed per the regular Load Balancer pricing.

    kubectl expose deployment hello-node --type="LoadBalancer"
    
  5. Copy the external IP address for the hello-node app

    kubectl get service hello-node
    
  6. View the app (replace EXTERNAL-IP with the external IP address you obtained in the previous step).

    http://EXTERNAL-IP:8080
    

Clean up

To avoid incurring charges to your Google Cloud Platform account for the resources used in this quickstart:

  1. Delete the services you created to remove the load balancing resources that are provisioned to serve them:

    kubectl delete service hello-node
    
  2. Wait a few minutes for the service to spin down, then use the following command to delete the cluster you created:

    gcloud container clusters delete example-cluster
    

What's next

Hello Node code review

Hello Node is an extremely simple app, consisting of just two files. This section describes those files.

server.js

The server.js file responds to any request by sending a response containing the message Hello Kubernetes.

var http = require('http');
var handleRequest = function (req, res) {
  res.writeHead(200);
  res.end('Hello Kubernetes!');
};
var www = http.createServer(handleRequest);
www.listen(process.env.PORT || 8080);

Dockerfile

The dockerfile describes the image you want to build, and specifies which port the app should listen on.

FROM node:6-alpine
EXPOSE 8080
COPY server.js .
CMD node server.js

Install the gcloud command-line tool

As an alternative to Cloud Shell, you can install the gcloud command-line tool on your local computer. The Container Engine API uses the gcloud command-line tool for cluster operations and for managing credentials.

  1. Install the Google Cloud SDK, which includes the gcloud command-line tool.
  2. Use the gcloud command-line tool to install the kubectl command-line tool:

    gcloud components install kubectl
    

Try one of the following tutorials to build and deploy and application from start to finish:

If you'd like to get started on your own, your first step is to create a container cluster.

Kubernetes and kubectl

Google Container Engine uses Kubernetes for container management, deployment and scaling. More information on Kubernetes is available on the external Kubernetes site.

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

Send feedback about...

Container Engine Documentation