k8s-workshop

GOALS:

At the end of the workshop, you should be able to:

Prerequisites

1 Watch this video

high level overview

2 Create a Cluster on Google Kubernetes Engine (GKE)

# Quick and easy
gcloud container clusters create {cluster-name} --project {google-cloud-project-id} --machine-type g1-small

# By default:
# --num-nodes "3"
# --machine-type "g1-small"
# --machine-type "n1-standard-1"

# Wire you kubectl client into the cluster, by updating config with right credentials
gcloud container clusters get-credentials {cluster-name}

More Info on GKE

Part 1: Hello World

For our Hello World exercise, we will deploy an app containing a bunch of nginx containers.

GOALS:

Check your setup

If you followed the instructions correctly to create a container cluster, your kubectl should be wired into your GKE cluster by now. You can verify that with:

kubectl config current-context

The output should look something like this:

gke_{project_name}_{zone}_{cluster_name}

If not, run gcloud container clusters get-credentials with the correct arguments, which you can get from your Google Cloud Console.

Now that everything is setup, let’s deploy! :)

Deploy our app

# create a Deployment, containing a ReplicaSet (of 3 pods), each of them containing a nginx container
kubectl run --image=nginx hello-nginx --port=80 --labels="app=hello" --replicas=3

# expose your Pods within the hello-nginx Deployment outside the cluster.
kubectl expose deployment hello-nginx --port=80 --name=hello-http --type=LoadBalancer

# grab the "LoadBalancer Ingress"
kubectl describe svc hello-http

# or if you have "watch" installed
watch -d "kubectl describe svc hello-http"

# If you look at the events at the bottom,
# one of the messages would be "Creating load balancer"
#
# Once you see the message "Created load balancer",
# you can proceed by accessing your app through the LoadBalancer Ingress address above

Congrats! You just deployed an app on Kubernetes!

The approach that we took to deploy is known as the imperative way. (imperative vs declarative: more on that later)

By now, you should have created the following resources:

Please take a look at the resources (deployment, replicasets, pods and services) you just deployed with the following commands:

kubectl get {resource-type}                             # e.g. kubectl get deployment
kubectl describe {resource-type} {resource-name}        # e.g. kubectl describe deployment hello-nginx

Once you have familiarized with the attributes of the resources, please remove them all by:

kubectl delete svc hello-http
kubectl delete deployment hello-nginx

Questions to ask yourself

In the Deploy our app section, we deployed an app and exposed it by running some commands (run and expose). And as mentioned, this way is known as the imperative way.


What you have learned in this section

  1. How to create a container-cluster on Google Kubernetes Engine (a.k.a. GKE)
  2. Wire your kubectl client to the correct GKE cluster
  3. Familiarize with the key resources within Kubernetes (Pods, ReplicaSets, Deployments, and Services)
  4. Learned how to interact with K8s resources by kubectl get, describe and delete
  5. Quickly deployed all these resources in one go with kubectl run, which is the imperative way of deployment.

This was a very high-level overview of Kubernetes. From here on, we will build your knowledge from the bottom up, starting by looking at Pods in the next section