kubernetes/examples/update-demo
Robert Bailey e0cc7b4138 Remove the numbered shell scripts from the live update example and the
update.sh e2e test. They were needlessly obfuscating the actual kubectl
commands being run.
2015-02-18 17:02:44 -08: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
build-images.sh Remove the numbered shell scripts from the live update example and the 2015-02-18 17:02:44 -08:00
kitten-rc.yaml Remove the numbered shell scripts from the live update example and the 2015-02-18 17:02:44 -08:00
nautilus-rc.yaml Remove the numbered shell scripts from the live update example and the 2015-02-18 17:02:44 -08:00
README.md Remove the numbered shell scripts from the live update example and the 2015-02-18 17:02:44 -08:00

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

If you are running your cluster on GCE (the default), 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 \
  kubernetes-minion-8080

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.

$ ./cluster/kubectl.sh proxy --www=local/ &
+ ./cluster/kubectl.sh proxy --www=local/
I0218 15:18:31.623279   67480 proxy.go:36] 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

$ ./cluster/kubectl.sh create -f examples/update-demo/nautilus-rc.yaml

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:

$ ./cluster/kubectl.sh resize rc update-demo-nautilus --replicas=4

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.

$ ./cluster/kubectl.sh rollingupdate update-demo-nautilus --update-period=10s -f examples/update-demo/kitten-rc.yaml

The rollingupdate command in kubectl will do 2 things:

  1. Create a new replication controller with a pod template that uses the new image (kubernetes/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

$ ./cluster/kubectl.sh stop rc update-demo-kitten

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                 ./cluster/kubectl.sh proxy --www=local/ &
$ kill %1
[1]+  Terminated: 15          ./cluster/kubectl.sh proxy --www=local/

Updating the Docker images

If you want to build your own docker images, you can set $DOCKER_HUB_USER to your Docker user id and run the included shell script. It can take a few minutes to download/upload stuff.

$ export DOCKER_HUB_USER=my-docker-id
$ ./examples/update-demo/build-images.sh

To use your custom docker image in the above examples, you will need to change the image name in examples/update-demo/nautilus-rc.yaml and examples/update-demo/kitten-rc.yaml.

Note that he images included here are public domain.