This is a demo of creating the subnets needed for a GKE Cluster
Create the base network for GKE.
gcloud compute networks create my-vpc-network \
--subnet-mode=custom
Create the base subnet and the secondary range subnets. The secondary range subnets include ranges for the pods and the services.
gcloud compute networks subnets create my-cluster-nodes-subnet \
--network my-vpc-network \
--region us-central1 \
--range 10.0.0.0/24 \
--secondary-range my-cluster-pod-subnet=10.1.0.0/16,my-cluster-service-subnet=10.2.0.0/20
We are creating a subnet for the hosts called my-cluster-host-subnet
. Within that subnet we are adding a secondary ranges for the pods and services; my-cluster-pod-subnet
, my-cluster-service-subnet
.
gcloud container clusters create my-cluster \
--region us-central1 \
--network=my-vpc-network \
--enable-ip-alias \
--subnetwork=my-cluster-nodes-subnet \
--cluster-secondary-range-name=my-cluster-pod-subnet \
--services-secondary-range-name=my-cluster-service-subnet \
--num-nodes=1
The cluster will use the following subnets.
Type | Subnet | IP Range |
---|---|---|
Nodes |
my-cluster-nodes-subnet |
10.0.0.0/24 |
Pods |
my-cluster-pod-subnet |
10.1.0.0/16 |
Service |
my-cluster-service-subnet |
10.2.0.0/20 |
k run hello-world --image=gcr.io/google-samples/hello-app:1.0 --port 8080
k expose deployment hello-world --type=LoadBalancer --name=hello-service
The following commands will show the different IP address that are being used.
This sometimes is done automatically. But good hygiene denotes to do it.
k delete svc --all
Delete the cluster
gcloud container clusters delete my-cluster \
--region us-central1
Delete the subnetwork
gcloud compute networks subnets delete my-cluster-nodes-subnet \
--region us-central1
Finally remove the network.
gcloud compute networks delete my-vpc-network
Typo in the "Create the Subnets" section: the command creates subnet "my-cluster-nodes-subnet", but the text refers to it as "my-cluster-host-subnet"