This codelab walks you through creating a container cluster on Google Container Engine. It is based on a tutorial published by Google and updated here to make use of some of the newest features in the Google Developers Console. You manage your cluster and Kubernetes (k8s) from Google Cloud Shell. You store and review your k8s configuration files in Google Cloud Source Repositories. You complete the entire codelab from your browser without installing any software locally.
1 - Sign up for a Google Cloud Platform free trial here: https://cloud.google.com/free-trial/
2 - Create a Google Cloud Platform project here: https://console.developers.google.com/project
3 - Enable the Google Compute Engine API: click Gallery -> Compute Engine, the API enables automactically
Compute Engine: Infrastructure as a Service, compute, storage and networking resources, in Google Cloud Platform.
Container: A virtual environment running at the operating-system level.
Docker: A Linux-based container format.
k8s: Common abbreviation of Kubernetes.
kubectl: Command line utility for managing Kubernetes.
Kubernetes: Container scheduler developed by Google in 2014.
Pod: Ephemeral grouping of containers to facilitate data sharing and communication within the group.
Replication Controller: Orchestrates the number and availability of Pods.
Service: Abstration for accessing groups of Pods using an IP and port pair.
Zone: An isolated location to run computing resources.
###Prepare your project
Configure Google Cloud Shell. Download the code you need to configure your cluster. Commit the code to your project repository.
Click Try the beta console.
Click Activate Google Cloud Shell.
List the available Compute Engine zones:
gcloud compute zones list
Pick one of the zones in Europe and set it as your default zone:
gcloud config set compute/zone ZONE
Make a directory to host the course code for the lab:
mkdir k8s-codelab
Change directory to k8s-codelab:
cd k8s-codelab
Clone your default Google Cloud Platform project repository:
gcloud source repos clone default
Change directory to default:
cd default
Download the config files for the lab:
wget https://cloud.google.com/container-engine/docs/tutorials/guestbook/guestbook.zip
Unzip the download:
unzip guestbook.zip
Remove the zip file:
rm guestbook.zip
Add all the config files to your repository:
git add .
Commit the new files to your repository:
git commit
Type the following commit message:
Guestbook config files
Type the following key comibination to exit the editor:
CTRL+X
Confirm that you want to exit and write the changes:
y
Push your changes to your repository:
git push origin master
Click Gallery -> Development
###Create a Container Cluster
Create a container cluster:
gcloud container clusters create guestbook
Describe your new cluster:
gcloud container clusters describe guestbook
###Create Redis master and worker Services
Use kubectl to manage and configure your k8s cluster. Review each configuration file in your repository before deploying it using kubectl.
Click redis-master-controller.yaml to examine the configuration for the Redis master Replication Controller.
Create a replication controller:
kubectl create -f redis-master-controller.yaml
List the pods running in your cluster:
kubectl get pods
List the names of the nodes running your pods, note the name of the node running your pod:
kubectl get pods -o wide
SSH to the node you noted in the previous step:
gcloud compute ssh NODE
List the Docker containers running on the node and note the container-id for the redis-master container:
sudo docker ps
View the logs for the redis-master container:
sudo docker logs CONTAINER-ID
Type the following to logout of the node:
CTRL+D
Click / -> redis-master-service.yaml to examine the configuration for the Redis master service.
Create a Redis master service:
kubectl create -f redis-master-service.yaml
List the services running in your cluster:
kubectl get services -l app=redis
Click / -> redis-worker-controller.yaml to examine the configuration for the Redis worker Replication Controller.
Create a Redis worker Replication Controller:
kubectl create -f redis-worker-controller.yaml
List the Pods running in your cluster, note the new workers:
kubectl get pods
Click / -> redis-worker-service.yaml to examine the configuration for the worker service.
Create a Redis worker Service:
kubectl create -f redis-worker-service.yaml
List the Services running in your cluster, note the new worker service:
kubectl get services
###Create a Web Frontend Service
Click / -> frontend-controller.yaml to examine the configuration for the web frontend Replicaiton Controller.
Create a web frontend Replication Controller:
kubectl create -f frontend-controller.yaml
List the Replication Controllers in your cluster:
kubectl get rc
List the Pods in your cluster:
kubectl get pods
Click / -> frontend-service.yaml to examine the configuration for the web frontend Service.
Create the web frontend service:
kubectl create -f frontend-service.yaml
List the Services in your cluster:
kubectl get services
View the frontend Service:
kubectl get services frontend
###Test Guestbook
Run the following command to view the IP address of your frontend load balancer:
Note: You may have to run this a few times before the value is available.
kubectl describe services frontend | grep "LoadBalancer Ingress"
Visit the IP address in a new tab in your browser to view and test Guestbook.
List the current number of Pods in your cluster:
kubectl get pods
Manually scale the number of frontend replic pods in your cluster:
kubectl scale --replicas=5 rc frontend
List the updated number of Pods in your cluster:
kubectl get pods
Click Gallery -> Compute Engine to view a summary of the individual virtual machines that make up your cluster.
IMPORTANT! This is the end of the codelab. The following steps delete your cluster so you don't incuur additional charges.
Delete the frontend service:
kubectl delete services frontend
Delete the guestbook cluster:
gcloud container clusters delete guestbook
Close Google Cloud Shell.
Based on https://cloud.google.com/container-engine/docs/tutorials/guestbook, licensed under the Creative Commons Attribution 3.0 License.