In Kubernetes Engine, a private cluster is a cluster that makes your master inaccessible from the public internet. In a private cluster, nodes do not have public IP addresses, only private addresses, so your workloads run in an isolated environment. Nodes and masters communicate with each other using VPC peering.
In the Kubernetes Engine API, address ranges are expressed as Classless Inter-Domain Routing (CIDR) blocks.
In this lab, you learn how to create a private Kubernetes cluster.
What you'll do
Create a Private Kubernetes Cluster.
Prerequisites
Student should already have experience creating and launching Kubernetes Clusters and be thoroughly versed in IP addressing in CIDR Range formats.
Setup and requirements
Before you click the Start Lab button
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources are made available to you.
This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
Access to a standard internet browser (Chrome browser recommended).
Note: Use an Incognito (recommended) or private browser window to run this lab. This prevents conflicts between your personal account and the student account, which may cause extra charges incurred to your personal account.
Time to complete the lab—remember, once you start, you cannot pause a lab.
Note: Use only the student account for this lab. If you use a different Google Cloud account, you may incur charges to that account.
How to start your lab and sign in to the Google Cloud console
Click the Start Lab button. If you need to pay for the lab, a dialog opens for you to select your payment method.
On the left is the Lab Details pane with the following:
The Open Google Cloud console button
Time remaining
The temporary credentials that you must use for this lab
Other information, if needed, to step through this lab
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
Note: If you see the Choose an account dialog, click Use Another Account.
If necessary, copy the Username below and paste it into the Sign in dialog.
{{{user_0.username | "Username"}}}
You can also find the Username in the Lab Details pane.
Click Next.
Copy the Password below and paste it into the Welcome dialog.
{{{user_0.password | "Password"}}}
You can also find the Password in the Lab Details pane.
Click Next.
Important: You must use the credentials the lab provides you. Do not use your Google Cloud account credentials.
Note: Using your own Google Cloud account for this lab may incur extra charges.
Click through the subsequent pages:
Accept the terms and conditions.
Do not add recovery options or two-factor authentication (because this is a temporary account).
Do not sign up for free trials.
After a few moments, the Google Cloud console opens in this tab.
Note: To access Google Cloud products and services, click the Navigation menu or type the service or product name in the Search field.
Activate Cloud Shell
Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.
Click Activate Cloud Shell at the top of the Google Cloud console.
Click through the following windows:
Continue through the Cloud Shell information window.
Authorize Cloud Shell to use your credentials to make Google Cloud API calls.
When you are connected, you are already authenticated, and the project is set to your Project_ID, . The output contains a line that declares the Project_ID for this session:
Your Cloud Platform project in this session is set to {{{project_0.project_id | "PROJECT_ID"}}}
gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
(Optional) You can list the active account name with this command:
gcloud auth list
Click Authorize.
Output:
ACTIVE: *
ACCOUNT: {{{user_0.username | "ACCOUNT"}}}
To set the active account, run:
$ gcloud config set account `ACCOUNT`
(Optional) You can list the project ID with this command:
gcloud config list project
Output:
[core]
project = {{{project_0.project_id | "PROJECT_ID"}}}
Note: For full documentation of gcloud, in Google Cloud, refer to the gcloud CLI overview guide.
Task 1. Set the region and zone
Set the project region for this lab:
gcloud config set compute/zone {{{project_0.default_zone | "Zone"}}}
Note: When you run gcloud on your own machine, the config settings are persisted across sessions. But in Cloud Shell, you need to set this for every new session or reconnection.
Task 2. Creating a private cluster
When you create a private cluster, you must specify a /28 CIDR range for the VMs that run the Kubernetes master components and you need to enable IP aliases.
Next you'll create a cluster named private-cluster, and specify a CIDR range of 172.16.0.16/28 for the masters. When you enable IP aliases, you let Kubernetes Engine automatically create a subnetwork for you.
You'll create the private cluster by using the --private-cluster, --master-ipv4-cidr, and --enable-ip-alias flags.
Click Check my progress to verify your performed task. If you have successfully created a private cluster, you will see an assessment score.
Create a private cluster
Task 3. View your subnet and secondary address ranges
List the subnets in the default network:
gcloud compute networks subnets list --network default
In the output, find the name of the subnetwork that was automatically created for your cluster. For example, gke-private-cluster-subnet-xxxxxxxx. Save the name of the cluster, you'll use it in the next step.
Now get information about the automatically created subnet, replacing [SUBNET_NAME] with your subnet by running:
In the output you can see that one secondary range is for pods and the other secondary range is for services.
Notice that privateIPGoogleAccess is set to true. This enables your cluster hosts, which have only private IP addresses, to communicate with Google APIs and services.
Task 4. Enable master authorized networks
At this point, the only IP addresses that have access to the master are the addresses in these ranges:
The primary range of your subnetwork. This is the range used for nodes.
The secondary range of your subnetwork that is used for pods.
To provide additional access to the master, you must authorize selected address ranges.
Create a VM instance
Create a source instance which you'll use to check the connectivity to Kubernetes clusters:
Copy the <nat_IP> address and save it to use in later steps.
Run the following to Authorize your external address range, replacing [MY_EXTERNAL_RANGE] with the CIDR range of the external addresses from the previous output (your CIDR range is natIP/32). With CIDR range as natIP/32, we are allowlisting one specific IP address:
gcloud container clusters update private-cluster \
--enable-master-authorized-networks \
--master-authorized-networks [MY_EXTERNAL_RANGE]
Note:
In a production environment replace [MY_EXTERNAL_RANGE] with your network external address CIDR range.
Test completed task
Click Check my progress to verify your performed task. If you have successfully authorized external address range, you will see an assessment score.
Authorize your external address range
Now that you have access to the master from a range of external addresses, you'll install kubectl so you can use it to get information about your cluster. For example, you can use kubectl to verify that your nodes do not have external IP addresses.
SSH into source-instance with:
gcloud compute ssh source-instance --zone=$ZONE
Press Y to continue. Enter through the passphrase questions.
In SSH shell install kubectl component of Cloud-SDK:
sudo apt-get install kubectl
Configure access to the Kubernetes cluster from SSH shell with:
sudo apt-get install google-cloud-sdk-gke-gcloud-auth-plugin
gcloud container clusters get-credentials private-cluster --zone=$ZONE
Note: Please make sure that the assigned zone has been exported in the ZONE variable.
Verify that your cluster nodes do not have external IP addresses:
kubectl get nodes --output yaml | grep -A4 addresses
The output shows that the nodes have internal IP addresses but do not have external addresses:
Here is another command you can use to verify that your nodes do not have external IP addresses:
kubectl get nodes --output wide
The output shows an empty column for EXTERNAL-IP:
STATUS ... VERSION EXTERNAL-IP OS-IMAGE ...
Ready v1.8.7-gke.1 Container-Optimized OS from Google
Ready v1.8.7-gke.1 Container-Optimized OS from Google
Ready v1.8.7-gke.1 Container-Optimized OS from Google
Click Check my progress to verify your performed task. If you have successfully deleted the Kubernetes cluster, you will see an assessment score.
Delete the Kubernetes cluster
Task 6. Create a private cluster that uses a custom subnetwork
In the previous section Kubernetes Engine automatically created a subnetwork for you. In this section, you'll create your own custom subnetwork, and then create a private cluster.
Your subnetwork has a primary address range and two secondary address ranges.
Click Check my progress to verify your performed task. If you have successfully created a subnetwork and secondary ranges in region, you will see an assessment score.
Create a subnetwork and secondary ranges in region
Create a private cluster that uses your subnetwork:
Click Check my progress to verify your performed task. If you have successfully created a private cluster that uses your subnetwork, you will see an assessment score.
Create a private cluster that uses your subnetwork
Retrieve the external address range of the source instance:
Copy the <nat_IP> address and save it to use in later steps.
Run the following to Authorize your external address range, replacing [MY_EXTERNAL_RANGE] with the CIDR range of the external addresses from the previous output (your CIDR range is natIP/32). With CIDR range as natIP/32, we are allowlisting one specific IP address:
Click Check my progress to verify your performed task. If you have successfully authorized your external address range for a private cluster in a custom subnetwork, you will see an assessment score.
Authorize your external address range for private cluster in custom subnetwork
SSH into source-instance with:
gcloud compute ssh source-instance --zone=$ZONE
Configure access to the Kubernetes cluster from SSH shell with:
gcloud container clusters get-credentials private-cluster2 --zone=$ZONE
Note: Please make sure that the assigned zone has been exported in the ZONE variable.
Verify that your cluster nodes do not have external IP addresses:
kubectl get nodes --output yaml | grep -A4 addresses
The output shows that the nodes have internal IP addresses but do not have external addresses:
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Manual Last Updated April 15, 2024
Lab Last Tested September 20, 2023
Copyright 2025 Google LLC. All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
I lab creano un progetto e risorse Google Cloud per un periodo di tempo prestabilito
I lab hanno un limite di tempo e non possono essere messi in pausa. Se termini il lab, dovrai ricominciare dall'inizio.
In alto a sinistra dello schermo, fai clic su Inizia il lab per iniziare
Utilizza la navigazione privata
Copia il nome utente e la password forniti per il lab
Fai clic su Apri console in modalità privata
Accedi alla console
Accedi utilizzando le tue credenziali del lab. L'utilizzo di altre credenziali potrebbe causare errori oppure l'addebito di costi.
Accetta i termini e salta la pagina di ripristino delle risorse
Non fare clic su Termina lab a meno che tu non abbia terminato il lab o non voglia riavviarlo, perché il tuo lavoro verrà eliminato e il progetto verrà rimosso
Questi contenuti non sono al momento disponibili
Ti invieremo una notifica via email quando sarà disponibile
Bene.
Ti contatteremo via email non appena sarà disponibile
Un lab alla volta
Conferma per terminare tutti i lab esistenti e iniziare questo
Utilizza la navigazione privata per eseguire il lab
Utilizza una finestra del browser in incognito o privata per eseguire questo lab. In questo modo eviterai eventuali conflitti tra il tuo account personale e l'account Studente, che potrebbero causare addebiti aggiuntivi sul tuo account personale.
Hands-on lab for creating a private cluster in the cloud environment. In a private cluster, nodes do not have public IP addresses, so your workloads run in an environment that is isolated from the Internet. Prerequisites: Experience with Kubernetes Clusters, and CIDR-range IP address.
Durata:
Configurazione in 0 m
·
Accesso da 90 m
·
Completamento in 90 m