To create a Google Kubernetes Engine (GKE) cluster, follow these steps:
- Enable the Kubernetes Engine API:
- Go to the Google Cloud Console: https://console.cloud.google.com/
- Select your project from the project dropdown.
- Click on the navigation menu (three horizontal lines) in the top left corner.
- Go to “APIs & Services” > “Dashboard.”
- Click on “+ ENABLE APIS AND SERVICES” at the top of the page.
- Search for “Kubernetes Engine API” and click on it.
- Click “Enable” to enable the API for your project.
- Install the Google Cloud SDK:
- Follow the instructions for your operating system here: https://cloud.google.com/sdk/docs/install
- Authenticate with your Google Cloud account:
- Open a terminal or command prompt.
- Run the following command:
gcloud auth login
- Follow the prompts to authenticate with your Google Cloud account.
- Set your project and compute zone:
- Run the following command to set your project:
gcloud config set project PROJECT_ID(replace
PROJECT_IDwith your project’s ID)
- Run the following command to set your compute zone:
gcloud config set compute/zone COMPUTE_ZONE(replace
COMPUTE_ZONEwith your desired compute zone, e.g.,
- Create the GKE cluster:
- Run the following command to create a GKE cluster:
gcloud container clusters create CLUSTER_NAME(replace
CLUSTER_NAMEwith your desired cluster name)
- This command will create a GKE cluster with the default settings (3 nodes, n1-standard-1 machine type, etc.). You can customize the cluster settings by adding flags to the command. For example, to create a cluster with 5 nodes and n1-standard-2 machine type, run:
gcloud container clusters create CLUSTER_NAME --num-nodes=5 --machine-type=n1-standard-2
- Configure kubectl to use the new cluster:
- Run the following command to get the cluster credentials:
gcloud container clusters get-credentials CLUSTER_NAME(replace
CLUSTER_NAMEwith your cluster name)
- This command will configure kubectl to use the new GKE cluster.
- Verify that the cluster is running:
- Run the following command to list your clusters:
gcloud container clusters list
- You should see your new cluster in the list with the status “RUNNING.”
Now you have successfully created a GKE cluster. You can start deploying applications to the cluster using kubectl.