Skip to content

How to Create a GKE Cluster

Last validated:
View as Markdown

WHAT TO EXPECT

In this section, users will learn how to deploy a GKE cluster with either traditional CNI, Cilium CNI or Calico CNI installed. Creating a managed Kubernetes cluster is a prerequisite to have an operational xNIC DaemonSet.

Before You Start

The cloudSwXtch VM instance needs to comply with the following requirements before you set up your GKE Cluster:

  • cloudSwXtch Tag version: The chosen tag must have support for Kubernetes clusters
  • VPC Peering: This must be active between the VPC for the REPL interface and the VPC for the CTRL interface

Enable Kubernetes Engine API

  1. Open Google Cloud CloudShell terminal.

GKE_CloudShell

  1. Change the authorization so that you're allowed to create the cluster.
gcloud services enable container.googleapis.com
  1. Validate the change by running the following command:
gcloud services list --enabled

Below is an example of what you should get as an output. You should see "Kubernetes Engine API" listed.

onna_silveri@cloudshell:~ (swxtch-sa-project)$ gcloud services list --enabled
NAME: artifactregistry.googleapis.com
TITLE: Artifact Registry API

NAME: autoscaling.googleapis.com
TITLE: Cloud Autoscaling API

NAME: bigquery.googleapis.com
TITLE: BigQuery API

NAME: bigquerymigration.googleapis.com
TITLE: BigQuery Migration API

NAME: bigquerystorage.googleapis.com
TITLE: BigQuery Storage API

NAME: cloudapis.googleapis.com
TITLE: Google Cloud APIs

NAME: cloudbuild.googleapis.com
TITLE: Cloud Build API

NAME: cloudfunctions.googleapis.com
TITLE: Cloud Functions API

NAME: cloudresourcemanager.googleapis.com
TITLE: Cloud Resource Manager API

NAME: cloudtrace.googleapis.com
TITLE: Cloud Trace API

NAME: compute.googleapis.com
TITLE: Compute Engine API

NAME: container.googleapis.com
TITLE: Kubernetes Engine API

NAME: containerfilesystem.googleapis.com
TITLE: Container File System API

NAME: containerregistry.googleapis.com
TITLE: Container Registry API

NAME: datastore.googleapis.com
TITLE: Cloud Datastore API

NAME: dns.googleapis.com
TITLE: Cloud DNS API

NAME: iam.googleapis.com
TITLE: Identity and Access Management (IAM) API

NAME: iamcredentials.googleapis.com
TITLE: IAM Service Account Credentials API

NAME: logging.googleapis.com
TITLE: Cloud Logging API

NAME: monitoring.googleapis.com
TITLE: Cloud Monitoring API

NAME: networkconnectivity.googleapis.com
TITLE: Network Connectivity API

NAME: oslogin.googleapis.com
TITLE: Cloud OS Login API

NAME: pubsub.googleapis.com
TITLE: Cloud Pub/Sub API

NAME: run.googleapis.com
TITLE: Cloud Run Admin API

NAME: servicemanagement.googleapis.com
TITLE: Service Management API

NAME: serviceusage.googleapis.com
TITLE: Service Usage API

NAME: source.googleapis.com
TITLE: Legacy Cloud Source Repositories API

NAME: sql-component.googleapis.com
TITLE: Cloud SQL

NAME: storage-api.googleapis.com
TITLE: Google Cloud Storage JSON API

NAME: storage-component.googleapis.com
TITLE: Cloud Storage

NAME: storage.googleapis.com
TITLE: Cloud Storage API

Creating the GKE Cluster

Once Kubernetes engine is enabled, a user will then have to decide which CNI plugin they would like to use. Depending on that decision, the command to create the GKE will vary:

Please note: The default number of nodes per cluster is set to 3 with each running the proprietary OS from Google (Container Optimized OS.)

To verify your settings, use the following command, replacing with your desired value.

gcloud container get-server-config -z <AVAILABILITY ZONE>

Updating Number of Nodes and Image Type

Following each command for network plugin, a user can change the number of nodes and the image type:

  • Number of Nodes: When creating a new GKE cluster, the default number of nodes per cluster is set to 3. In the event that you would like to change this, use the argument --num-nodes at the end of the installation command, followed by the number you would like per cluster. (Example: --num-nodes 2)
  • Image Type (Ubuntu): By default, GKE runs on a proprietary OS from Google (Container Optimized OS). If you would like Ubuntu running on the nodes, add the --image-type argument at the end of the command, followed by UBUNTU_CONTAINERD. (Example: --image-type UBUNTU_CONTAINERD)

GKE with Traditional CNI

Run the following command, replacing with what you want to name the cluster and with the availability zone you desire. This will give you the default 3 nodes per cluster on Google Container Optimized OS.

gcloud container clusters create <CLUSTER-NAME> --zone <AVAILABILITY ZONE>

Below is an example of a user setting up a GKE with the traditional CNI named "gke-cluster-la" in availability zone "us-central1-a", changing the number of nodes and the image type:

gcloud container clusters create gke-cluster-1a --zone us-central1-a --num-nodes 2 --image-type UBUNTU_CONTAINERD

Your GKE cluster is now installed. Continue on to the Verifying Installation section to finish.

GKE with Calico CNI

If you prefer to use Calico CNI to manage the network, add the --enable-network argument to the cluster creation command:

gcloud container clusters create <CLUSTER-NAME> --zone <AVAILABILITY-ZONE> \ --enable-network-policy

Your GKE cluster with Calico CNI is now installed. Continue on to the Verifying Installation section to finish.

GKE with Cilium CNI

If you prefer to use Cilium CNI to manage the network, add the --node-taints argument to the command to avoid scheduling Pods on the nodes when Cilium is not yet installed. The following command will create your cluster:

gcloud container clusters create <CLUSTER-NAME> --zone <AVAILABILITY-ZONE> \
--node-taints node.cilium.io/agent-not-ready=true:NoExecute

If you selected Cilium as your network plugin for your cluster, continue to the Installing Cilium CNI section.


Installing Cilium CNI for GKE Cluster

Step One: Install Cilium CLI utility

  1. Run the following shell script in your Google Cloud CloudShell to install Cilium CLI on your system:
CILIUM_CLI_VERSION=$(curl -s https://raw.githubusercontent.com/cilium/cilium-cli/master/stable.txt)
CLI_ARCH=amd64
if [ "$(uname -m)" = "aarch64" ]; then CLI_ARCH=arm64; fi
curl -L --fail --remote-name-all https://github.com/cilium/cilium-cli/releases/download/${CILIUM_CLI_VERSION}/cilium-linux-${CLI_ARCH}.tar.gz{,.sha256sum}
sha256sum -c cilium-linux-${CLI_ARCH}.tar.gz.sha256sum
mkdir -p ~/bin
tar xzvf cilium-linux-${CLI_ARCH}.tar.gz -C /usr/local/bin -C ~/bin
export PATH=$PATH:~/bin
rm cilium-linux-${CLI_ARCH}.tar.gz{,.sha256sum}
  1. Run the following command to verify that it's been successfully installed:
cilium version --client

Example response

hpuy@cloudshell:~ (swxtch-vpc-host-nonprod)$ cilium version --client
cilium-cli: v0.15.5 compiled with go1.20.4 on linux/amd64
cilium image (default): v1.14.0
cilium image (stable): v1.14.0

Step Two: Install Cilium CNI

  1. Install CNI on the GKE Cluster, by simply running the following command:
cilium install
  1. Validate that it's been successfully installed:
cilium status

Example response

puy@cloudshell:~ (swxtch-vpc-host-nonprod)$ cilium status
    /¯¯\
 /¯¯\__/¯¯\    Cilium:             OK
 \__/¯¯\__/    Operator:           OK
 /¯¯\__/¯¯\    Envoy DaemonSet:    disabled (using embedded mode)
 \__/¯¯\__/    Hubble Relay:       disabled
    \__/       ClusterMesh:        disabled

DaemonSet              cilium             Desired: 3, Ready: 3/3, Available: 3/3
Deployment             cilium-operator    Desired: 1, Ready: 1/1, Available: 1/1
Containers:            cilium             Running: 3
                       cilium-operator    Running: 1
Cluster Pods:          18/18 managed by Cilium
Helm chart version:    1.14.0
Image versions         cilium             quay.io/cilium/cilium:v1.14.0@sha256:5a94b561f4651fcfd85970a50bc78b201cfbd6e2ab1a03848eab25a82832653a: 3
                       cilium-operator    quay.io/cilium/operator-generic:v1.14.0@sha256:3014d4bcb8352f0ddef90fa3b5eb1bbf179b91024813a90a0066eb4517ba93c9: 1

Your GKE cluster with Cilium CNI  is now installed. Continue on to the Verifying Installation section to finish.


Verifying Installation of GKE Cluster

You have completed the installation of a GKE cluster. In order to verify that the installation was successful, please run the following command from your terminal or Google CloudShell.

kubectl get pods -A

Updating kubectl Context

By default, Google CloudShell sessions include kubectl. However, in the event that you already have a cluster created and don't have credentials in your session to manage it, read the "Update kubectl context" section for more information.

Example response:

hpuy@cloudshell:~ (swxtch-vpc-host-nonprod)$ kubectl get pods -A
NAMESPACE     NAME                                                             READY   STATUS    RESTARTS       AGE
gmp-system    alertmanager-0                                                   2/2     Running   0              3h25m
gmp-system    collector-jgjrw                                                  2/2     Running   0              169m
gmp-system    collector-m8x5b                                                  2/2     Running   0              169m
gmp-system    collector-q6t56                                                  2/2     Running   0              169m
gmp-system    gmp-operator-6c98dd9bf9-p2qj2                                    1/1     Running   0              3h25m
gmp-system    rule-evaluator-598876fdc-kmpmm                                   2/2     Running   1 (169m ago)   169m
kube-system   cilium-6mfpv                                                     1/1     Running   0              6m34s
kube-system   cilium-d6vft                                                     1/1     Running   0              6m34s
kube-system   cilium-mkz6z                                                     1/1     Running   0              6m34s
kube-system   cilium-node-init-65fvq                                           1/1     Running   0              6m34s
kube-system   cilium-node-init-kmbqc                                           1/1     Running   0              6m34s
kube-system   cilium-node-init-wn279                                           1/1     Running   0              6m34s
kube-system   cilium-operator-76c55fc6b6-lmvb4                                 1/1     Running   0              6m34s
kube-system   event-exporter-gke-7bf6c99dcb-6pbcc                              2/2     Running   0              3h26m
kube-system   fluentbit-gke-jmv7f                                              2/2     Running   0              3h25m
kube-system   fluentbit-gke-llq9d                                              2/2     Running   0              3h25m
kube-system   fluentbit-gke-s28js                                              2/2     Running   0              3h25m
kube-system   gke-metrics-agent-9f55z                                          2/2     Running   0              3h25m
kube-system   gke-metrics-agent-nvb25                                          2/2     Running   0              3h25m
kube-system   gke-metrics-agent-wtrlt                                          2/2     Running   0              3h25m
kube-system   konnectivity-agent-877db59bd-7dgx2                               1/1     Running   0              3h26m
kube-system   konnectivity-agent-877db59bd-w9c6v                               1/1     Running   0              169m
kube-system   konnectivity-agent-877db59bd-zj55w                               1/1     Running   0              169m
kube-system   konnectivity-agent-autoscaler-5d9dbcc6d8-l7bcv                   1/1     Running   0              3h26m
kube-system   kube-dns-865c4fb86d-6fs67                                        4/4     Running   0              169m
kube-system   kube-dns-865c4fb86d-kcrk4                                        4/4     Running   0              3h26m
kube-system   kube-dns-autoscaler-84b8db4dc7-vrpf9                             1/1     Running   0              3h26m
kube-system   kube-proxy-gke-gke-ubuntu-cilium-1a-default-pool-cbfdb3dd-g18c   1/1     Running   0              3h24m
kube-system   kube-proxy-gke-gke-ubuntu-cilium-1a-default-pool-cbfdb3dd-htz4   1/1     Running   0              3h25m
kube-system   kube-proxy-gke-gke-ubuntu-cilium-1a-default-pool-cbfdb3dd-rtwj   1/1     Running   0              3h25m
kube-system   l7-default-backend-799dc5bb9-bq6rk                               1/1     Running   0              3h26m
kube-system   metrics-server-v0.5.2-6bf74b5d5f-kl8gp                           2/2     Running   1 (26m ago)    169m
kube-system   pdcsi-node-lhzgl                                                 2/2     Running   0              3h25m
kube-system   pdcsi-node-n4gs4                                                 2/2     Running   0              3h25m
kube-system   pdcsi-node-nwp45                                                 2/2     Running   0              3h25m
hpuy@cloudshell:~ (swxtch-vpc-host-nonprod)$

Installing xNIC in Kubernetes Cluster

After creating a GKE Cluster, continue on to Installing xNIC on Kubernetes Cluster for instructions on how to deploy an xNIC.


Optional: Update kubectl Context

  1. Run the following command to list the GKE Clusters you have on your account:
gcloud container clusters list

Example response:

hpuy@cloudshell:~ (swxtch-vpc-host-nonprod)$ gcloud container clusters list
NAME: gke-ubuntu-cilium-1a
LOCATION: us-central1-a
MASTER_VERSION: 1.27.2-gke.1200
MASTER_IP: 34.170.62.19
MACHINE_TYPE: e2-medium
NODE_VERSION: 1.27.2-gke.1200
NUM_NODES: 3
STATUS: RUNNING
hpuy@cloudshell:~ (swxtch-vpc-host-nonprod)$
  1. Identify the name and zone, and run the following command to have your kubeconfig file updated locally:
gcloud container clusters get-credentials <CLUSTER-NAME> -z <AVAILABILITY-ZONE>

Example response:

hpuy@cloudshell:~ (swxtch-vpc-host-nonprod)$ gcloud container clusters get-credentials gke-ubuntu-cilium-1a -z us-central1-a
Fetching cluster endpoint and auth data.
kubeconfig entry generated for gke-ubuntu-cilium-1a.
  1. Verify you have access to the cluster by using the following command:
kubectl get nodes

Example Response:

hpuy@cloudshell:~ (swxtch-vpc-host-nonprod)$ kubectl get nodes
NAME                                                  STATUS   ROLES    AGE    VERSION
gke-gke-ubuntu-cilium-1a-default-pool-cbfdb3dd-g18c   Ready    <none>   137m   v1.27.2-gke.1200
gke-gke-ubuntu-cilium-1a-default-pool-cbfdb3dd-htz4   Ready    <none>   137m   v1.27.2-gke.1200
gke-gke-ubuntu-cilium-1a-default-pool-cbfdb3dd-rtwj   Ready    <none>   137m   v1.27.2-gke.1200