k3s/examples/update-demo
Justin Santa Barbara c6f32d5a15 Stop both replication controllers in update-demo
The update test may have failed, and if we leave an RC around it
causes subsequent tests to fail
2015-02-11 12:54:18 -05:00
..
images Fix update-demo to work correctly with a web browser. 2014-12-10 12:34:19 -08:00
local Update update-demo example and e2e test to use kubectl 2015-01-28 15:26:56 -08:00
0-build-images.sh Change update example to use a trivial webserver instead of nginx (issue #1803). 2014-11-12 15:13:11 -08:00
1-run-web-proxy.sh Update update-demo example and e2e test to use kubectl 2015-01-28 15:26:56 -08:00
2-create-replication-controller.sh Fix update.sh 2015-01-28 20:00:47 -08:00
3-scale.sh Update update-demo example and e2e test to use kubectl 2015-01-28 15:26:56 -08:00
4-rolling-update.sh Update update-demo example and e2e test to use kubectl 2015-01-28 15:26:56 -08:00
5-down.sh Stop both replication controllers in update-demo 2015-02-11 12:54:18 -05:00
README.md Update update-demo example and e2e test to use kubectl 2015-01-28 15:26:56 -08:00
kitten-rc.yaml Update update-demo example and e2e test to use kubectl 2015-01-28 15:26:56 -08:00
nautilus-rc.yaml Update update-demo example and e2e test to use kubectl 2015-01-28 15:26:56 -08:00

README.md

Live update example

This example demonstrates the usage of Kubernetes to perform a live update on a running group of pods.

Step Zero: Prerequisites

This example assumes that you have forked the repository and turned up a Kubernetes cluster:

$ cd kubernetes
$ hack/dev-build-and-up.sh

This example also assumes that you have Docker installed on your local machine.

It also assumes that $DOCKER_HUB_USER is set to your Docker user id. We use this to upload the docker images that are used in the demo.

$ export DOCKER_HUB_USER=my-docker-id

You may need to open the firewall for port 8080 using the console or the gcloud tool. The following command will allow traffic from any source to instances tagged kubernetes-minion:

$ gcloud compute firewall-rules create \
  --allow tcp:8080 --target-tags=kubernetes-minion \
  --zone=us-central1-a kubernetes-minion-8080

Step Zero: Build the Docker images

This can take a few minutes to download/upload stuff.

$ cd examples/update-demo
$ ./0-build-images.sh

Step One: Turn up the UX for the demo

You can use bash job control to run this in the background. This can sometimes spew to the output so you could also run it in a different terminal.

$ ./1-run-web-proxy.sh &
Running local proxy to Kubernetes API Server.  Run this in a
separate terminal or run it in the background.

    http://localhost:8001/static/

+ ../../cluster/kubectl.sh proxy --www=local/
I0115 16:50:15.959551   19790 proxy.go:34] Starting to serve on localhost:8001

Now visit the the demo website. You won't see anything much quite yet.

Step Two: Run the controller

Now we will turn up two replicas of an image. They all serve on port 8080, mapped to internal port 80

$ ./2-create-replication-controller.sh

After pulling the image from the Docker Hub to your worker nodes (which may take a minute or so) you'll see a couple of squares in the UI detailing the pods that are running along with the image that they are serving up. A cute little nautilus.

Step Three: Try resizing the controller

Now we will increase the number of replicas from two to four:

$ ./3-scale.sh

If you go back to the demo website you should eventually see four boxes, one for each pod.

Step Four: Update the docker image

We will now update the docker image to serve a different image by doing a rolling update to a new Docker image.

$ ./4-rolling-update.sh

The rollingUpdate command in kubectl will do 2 things:

  1. Create a new replication controller with a pod template that uses the new image ($DOCKER_HUB_USER/update-demo:kitten)
  2. Resize the old and new replication controllers until the new controller replaces the old. This will kill the current pods one at a time, spinnning up new ones to replace them.

Watch the demo website, it will update one pod every 10 seconds until all of the pods have the new image.

Step Five: Bring down the pods

$ ./5-down.sh

This will first 'stop' the replication controller by turning the target number of replicas to 0. It'll then delete that controller.

Step Six: Cleanup

To turn down a Kubernetes cluster:

$ cd ../..  # Up to kubernetes.
$ cluster/kube-down.sh

Kill the proxy running in the background: After you are done running this demo make sure to kill it:

$ jobs
[1]+  Running                 ./1-run-web-proxy.sh &
$ kill %1
[1]+  Terminated: 15          ./1-run-web-proxy.sh

Note that he images included here are public domain.