This page explains how to create a container cluster on Kubernetes Engine.
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
To create a cluster using GCP Console, perform the following steps:
Visit the Kubernetes Engine menu in GCP Console.
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.
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]]
[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
--no-enable-basic-authis 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
--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
Viewing your clusters
To view your clusters, visit the Kubernetes Engine menu in GCP Console.
To see more information about a cluster, select a cluster from the list.
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
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
gcloud container clusters get-credentials [CLUSTER_NAME]
This command adds the cluster's authentication credentials to the
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
When you create a cluster using
gcloud, the cluster's authentication
credentials are added to the local
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
your desktop in order to access the cluster from that machine.
To learn more about clusters, refer to the following documentation:
- Learn about autoscaling your clusters.
- Learn how to set up multi-zone clusters.
- Learn how to create regional clusters.
- Learn how to label your clusters.
- Read about Node Auto-Upgrades.
- Read about Node Auto-Repair.
- Learn about preemptible VMs.
- Learn about using local SSDs.