IT 3300 : Virtualization

Kubernetes on Google

Install gcloud

I did the following on a machine that didn't have kubectl installed on it already. (I.e. like oxygen.cs.utahtech.edu)

  • wget and untar
  • Look here
  • Use Linux not Ubuntu
  • ./google-cloud-sdk/install.sh
  • source .bashrc
  • gcloud init (select or create a project)
  • gcloud components install kubectl
  • gcloud config set compute/zone us-central1-b

Attach billing account to project

Navigate to billing -> my projects -> click on 3 dots, and change to the account that you applied credits to.

Create cluster

  • Navigate to website and enable billing and cluster api
  • Create container cluster to run the container image (on GCP)
    • A cluster consists of a pool of Compute Engine VM instances running Kubernetes, the open source cluster orchestration system that powers Kubernetes Engine.
    • gcloud container clusters create hello-cluster --num-nodes=3
      • Creates a 3 node cluster named hello-cluster
  • Verify that you can see the cluster and VMs on GCP
  • gcloud container clusters get-credentials hello-cluster
  • Can also see instances via command line with:
    • gcloud compute instances list

Deploy

Deploy the application:

  • kubectl create deployment hello-server --image=gcr.io/google-samples/hello-app:1.0
    • This will run our app on the cluster
  • Practice some of our other K8s commands:
    • kubectl get nodes
    • kubectl get deployments
    • kubectl get pods
    • kubectl get services

Expose

Expose application to the internet:

  • kubectl expose deployment hello-server --type LoadBalancer \ --port 80 --target-port 8080

Expose

The above command creates a Service resource, which provides networking and IP support to your application's Pods. Kubernetes Engine creates an external IP and a Load Balancer for your application.

The --port flag specifies the port number configured on the Load Balancer, and the --target-port flag specifies the port number that is used by the Pod created by the kubectl run command

Get your service definitions again to see what external IP it is deployed on.

Should be able to visit in a browser.

Scale

See what you are currently using by:

  • kubectl get deployment hello-server

Scale:

  • kubectl scale deployment hello-server --replicas=2
    • Then see how many pods you are using.

Step 8

Deploying new versions of an app. Begin by changing the string of "Hello world" in the text file to something else.

  • rebuild (maybe put v2 at end of build statement)
  • repush
  • apply a rolling update
    • kubectl set image deployment/hello-web hello-web=gcr.io/${PROJECT_ID}/hello-app:v2

Rollback

Check status of deployment:

  • kubectl rollout status deployment/hello-web
  • kubectl get rs
  • kubectl describe deployment

Check Rollout history:

  • kubectl rollout history deployment/hello-web

Roll it back

  • kubectl rollout undo deployment/hello-web --to-revision=1 deployment/hello-web

Cleanup

  • Delete the service first
    • kubectl delete service hello-web
  • Wait for lb service to be deleted,
    • gcloud compute forwarding-rules list
  • Delete container cluster
    • gcloud container clusters delete hello-cluster
  • Double check in console