Setting up GKE and a sample K8s app

Updated: 5 days ago

The post shows how you can quickly set up a Kubernetes cluster in Google Cloud and run a sample Kubernetes app on it.


Setting up Kubernetes (GKE)

There are 2 ways to do this (1) console and (2) CLI


1) Console - go to GCP cloud and navigate to Kubernetes Engine under the Compute section. Click on "Clusters" for the page to open and select "Create a Cluster"







Now you can select a name, region, and version (stick with defaults)




Click "default-pool" under NODE POOLS on the left-hand sidebar to select "Enable Autoscaling" set the max to 6.












2) Command Line Interface (CLI)


Create a cluster

# With Ubuntu node VMs
$ gcloud container clusters create cluster-1-k8s-test --image-type ubuntu --enable-autoscaling --max-nodes=6 --min-nodes=3 --machine-type=e2-standard-4  

# With default node VMs
$ gcloud container clusters create cluster-1-k8s-test --enable-autoscaling --max-nodes=6 --min-nodes=2

Access your cluster


After the k8s cluster is created (either through CLI or console), the next step is to access it

$ gcloud container clusters get-credentials cluster-1-k8s-test
#Fetching cluster endpoint and auth data.
#kubeconfig entry generated for cluster-1-k8s-test.

#run kubectl to see if you can see the pods
$ kubectl get pods -A

#to check which cluster your are connected to
$ kubectl config current-context










Launching an opensource k8s app on your cluster

# Create a directory
mkdir google
cd google

# Download googleshopping app from git hub
git clone https://github.com/GoogleCloudPlatform/microservices-demo.git

# Go to the directory
cd microservices-demo/release

# Create a namespace
kubectl create ns gshop

# Run the file
kubectl apply -f kubernetes-manifests.yaml --namespace=gshop

# Get the IP for external service to log from a browser
kubectl get svc -A

Open a browser, log into the external IP, you should be able to see this page



12 views