Checkpoints
Create a private cluster
/ 10
Create a VM instance
/ 10
Authorize your external address range
/ 20
Delete the Kubernetes cluster
/ 20
Create a subnetwork and secondary ranges in us-central1 region
/ 10
Create a private cluster that uses your subnetwork
/ 10
Authorize your external address range for private cluster in custom subnetwork
/ 20
Setting up a Private Kubernetes Cluster
GSP178
Overview
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 will be made available to you.
This hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that 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).
- Time to complete the lab---remember, once you start, you cannot pause a lab.
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 pop-up opens for you to select your payment method. On the left is the Lab Details panel 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 panel.
-
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 panel.
-
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.
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.
When you are connected, you are already authenticated, and the project is set to your 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:
- Click Authorize.
Output:
- (Optional) You can list the project ID with this command:
Output:
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:
- Create a variable for region:
- Create a variable for zone:
Learn more from the Regions & Zones documentation.
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.
- Run the following to create the cluster:
Test completed task
Click Check my progress to verify your performed task. If you have successfully created a private cluster, you will see an assessment score.
Task 3. View your subnet and secondary address ranges
- List the subnets in the default network:
-
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:
The output shows you the primary address range with the name of your GKE private cluster and the secondary ranges:
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:
Test completed task
Click Check my progress to verify your performed task. If you have successfully created a VM instance, you will see an assessment score.
- Get the
<External_IP>
of thesource-instance
with:
Example Output:
-
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 isnatIP/32
). With CIDR range asnatIP/32
, we are allowlisting one specific IP address:
[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.
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:
-
Press
Y
to continue. Enter through the passphrase questions. -
In SSH shell install
kubectl
component of Cloud-SDK:
- Configure access to the Kubernetes cluster from SSH shell with:
ZONE
variable.
- Verify that your cluster nodes do not have external IP 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:
The output shows an empty column for EXTERNAL-IP
:
- Close the SSH shell by typing:
Task 5. Clean Up
- Delete the Kubernetes cluster:
- Press
Y
to continue.
Test completed task
Click Check my progress to verify your performed task. If you have successfully deleted the Kubernetes cluster, you will see an assessment score.
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.
- Create a subnetwork and secondary ranges:
Test completed task
Click Check my progress to verify your performed task. If you have successfully created a subnetwork and secondary ranges in
- Create a private cluster that uses your subnetwork:
Test completed task
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.
- Retrieve the external address range of the source instance:
Example Output:
-
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 isnatIP/32
). With CIDR range asnatIP/32
, we are allowlisting one specific IP address:
Test completed task
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.
- SSH into
source-instance
with:
- Configure access to the Kubernetes cluster from SSH shell with:
ZONE
variable.
- Verify that your cluster nodes do not have external IP addresses:
The output shows that the nodes have internal IP addresses but do not have external addresses:
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. In this example, the range for nodes is
10.0.4.0/22
. - The secondary range of your subnetwork that is used for pods. In this example, the range for pods is
10.4.0.0/14
.
Congratulations!
You learned how to create a private Kubernetes cluster.
Next steps / Learn more
- Check out these labs:
Google Cloud training and certification
...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 2024 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.