Creating a Container Cluster

This page explains how to create a container cluster on Kubernetes Engine.

Overview

When you create a cluster, you specify the number and type of node instances to create in the cluster. The node instances initially created in a cluster become the cluster's default node pool.

When you create a cluster, Kubernetes Engine creates a cluster master and nodes of the number and type you specify. Kubernetes Engine creates a firewall and network routes for the nodes, so the nodes can communicate with one another.

Creating a cluster

You can create a container cluster using the gcloud command-line tool or GCP Console.

Console

To create a cluster using GCP Console, perform the following steps:

  1. Visit the Kubernetes Engine menu in GCP Console.

    Visit the Kubernetes Engine menu

  2. Click Create cluster. The following fields are required:

    • Name: The name you choose for the cluster. It must be unique within the project and the zone.
    • Zone: Compute Engine compute zone in which to create the cluster.
    • Cluster size: The number of nodes to create in the cluster. You must have available resource quota for the nodes and their resources (such as firewall routes).
    • Machine type: Compute Engine machine type to use for the instances. Each machine type is billed differently. The default machine type is n1-standard-1. For pricing information, refer to the price sheet.
  3. Click Create.

gcloud

To create a container cluster with the gcloud command-line tool, use the gcloud container clusters command:

gcloud container clusters create [CLUSTER_NAME] [--zone [COMPUTE_ZONE]]

where [CLUSTER_NAME] is the name you choose for the cluster and [COMPUTE_ZONE] is the Compute Engine compute zone in which to create the cluster. The optional --zone flag overrides the default compute/zone property set by gcloud config set compute/zone.

Below are some optional flags that you can specify:

  • --additional-zones: The set of additional compute zones in which the cluster's node footprint should be replicated. All zones must be in the same region as the cluster's primary zone. The same node footprint is replicated in all zones, so a cluster with four nodes and two additional zones would have 12 nodes total (four in primary zone and four in each additional zone).
  • --enable-basic-auth: Enable basic (username/password) authentication for the cluster. This flag is an alias for --username=admin. --no-enable-basic-auth is an alias for --username="", which creates the cluster without basic HTTP authentication.
  • --image-type: The base node image that nodes in the cluster runs on. To see the default image type and the list of available image types, run gcloud container get-server-config.
  • --machine-type: Compute Engine machine type to use for nodes in the cluster. If omitted, the default machine type is n1-standard-1.
  • --num-nodes: The number of nodes to create in the cluster. You must have available resource quota for the nodes and their resources (such as firewall routes).

For the full list of optional flags, refer to the gcloud container clusters create documentation.

Viewing your clusters

Console

To view your clusters, visit the Kubernetes Engine menu in GCP Console.

Visit the Kubernetes Engine menu

To see more information about a cluster, select a cluster from the list.

gcloud

To view a specific cluster, run the following command:

gcloud container clusters describe [CLUSTER_NAME] [--zone [COMPUTE_ZONE]]

To view all clusters in a specific zone:

gcloud container clusters list [--zone [COMPUTE_ZONE]]

Setting the default cluster

If you have multiple clusters, you need to set a default cluster for the gcloud and kubectl command-line tools.

First, set the default cluster for gcloud by running the following command:

gcloud config set container/cluster [CLUSTER_NAME]

Then, pass the cluster's credentials to kubectl:

gcloud container clusters get-credentials [CLUSTER_NAME]

This command adds the cluster's authentication credentials to the kubeconfig file in your environment.

kubectl uses Application Default Credentials to authenticate to the cluster. To ensure that kubectl has the proper credentials, run:

gcloud auth application-default login

This command opens a browser window which prompts you to log in with your Google Cloud Platform account. After you successfully log in, the authentication credentials are generated.

Passing cluster credentials to kubectl

When you create a cluster using gcloud, the cluster's authentication credentials are added to the local kubeconfig file:

Creating cluster...done.
kubeconfig entry generated for cluster.

If you created a cluster using GCP Console or using gcloud on a different machine, you need to make the cluster's credentials available to kubectl in your current environment.

To pass the cluster's credentials to kubectl, run the following command:

gcloud container clusters get-credentials [CLUSTER_NAME] [--zone [COMPUTE_ZONE]]

You only need to run this once per cluster per machine; for example, if you created your cluster from your laptop, you need to run get-credentials on your desktop in order to access the cluster from that machine.

What's next

To learn more about clusters, refer to the following documentation:

Cluster features

Node features

Administering clusters

Cluster concepts

Send feedback about...

Kubernetes Engine