k3s/examples/update-demo/README.md

138 lines
4.4 KiB
Markdown
Raw Normal View History

2014-06-24 05:21:13 +00:00
<!--
Copyright 2014 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
# 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](https://github.com/GoogleCloudPlatform/kubernetes-new#contents):
2014-06-24 05:21:13 +00:00
2014-09-22 18:41:46 +00:00
```bash
$ cd kubernetes
$ hack/dev-build-and-up.sh
```
2014-06-24 05:21:13 +00:00
This example also assumes that you have [Docker](http://docker.io) 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.
2014-09-22 18:41:46 +00:00
```bash
$ export DOCKER_HUB_USER=my-docker-id
```
2014-06-24 05:21:13 +00:00
2014-11-25 18:32:27 +00:00
You may need to open the firewall for port 8080 using the [console][cloud-console] or the `gcloud` tool. The following command will allow traffic from any source to instances tagged `kubernetes-minion`:
2014-09-22 18:41:46 +00:00
```bash
2014-11-25 18:32:27 +00:00
$ gcloud compute firewall-rules create \
--allow tcp:8080 --target-tags=kubernetes-minion \
--zone=us-central1-a kubernetes-minion-8080
```
2014-09-22 18:41:46 +00:00
### Step Zero: Build the Docker images
This can take a few minutes to download/upload stuff.
2014-06-24 05:21:13 +00:00
2014-09-22 18:41:46 +00:00
```bash
$ cd examples/update-demo
$ ./0-build-images.sh
```
2014-06-24 05:21:13 +00:00
### Step One: Turn up the UX for the demo
2014-06-24 05:21:13 +00:00
2014-09-22 18:41:46 +00:00
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.
```
2014-09-22 18:41:46 +00:00
$ ./1-run-web-proxy.sh &
Running local proxy to Kubernetes API Server. Run this in a
separate terminal or run it in the background.
2014-06-24 05:21:13 +00:00
2014-09-22 18:41:46 +00:00
http://localhost:8001/static/
+ ../../cluster/kubecfg.sh -proxy -www local/
I0922 11:43:54.886018 15659 kubecfg.go:209] Starting to serve on localhost:8001
```
2014-06-24 05:21:13 +00:00
Now visit the the [demo website](http://localhost:8001/static). You won't see anything much quite yet.
2014-06-24 05:21:13 +00:00
### 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
2014-09-22 18:41:46 +00:00
```bash
$ ./2-create-replication-controller.sh
```
2014-09-22 18:41:46 +00:00
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.
2014-06-24 05:21:13 +00:00
### Step Three: Try resizing the controller
2014-06-24 05:21:13 +00:00
Now we will increase the number of replicas from two to four:
2014-09-22 18:41:46 +00:00
```bash
$ ./3-scale.sh
```
2014-06-24 05:21:13 +00:00
If you go back to the [demo website](http://localhost:8001/static/index.html) 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.
2014-06-24 05:21:13 +00:00
2014-09-22 18:41:46 +00:00
```bash
2014-10-15 21:12:03 +00:00
$ ./4-rolling-update.sh
2014-06-24 05:21:13 +00:00
```
The rollingUpdate command in kubecfg will do 2 things:
2014-06-24 05:21:13 +00:00
1. Update the template in the replication controller to the new image (`$DOCKER_HUB_USER/update-demo:kitten`)
2. Kill each of the pods one by one. It'll let the replication controller create new pods to replace those that were killed.
2014-06-24 05:21:13 +00:00
Watch the UX, it will update one pod every 10 seconds until all of the pods have the new image.
2014-06-24 05:21:13 +00:00
### Step Five: Bring down the pods
2014-06-24 05:21:13 +00:00
2014-09-22 18:41:46 +00:00
```bash
$ ./5-down.sh
```
2014-06-24 05:21:13 +00:00
This will first 'stop' the replication controller by turning the target number of replicas to 0. It'll then delete that controller.
[cloud-console]: https://console.developer.google.com
### Step Six: Cleanup
To turn down a Kubernetes cluster:
2014-09-22 18:41:46 +00:00
```bash
$ cd ../.. # Up to kubernetes.
$ cluster/kube-down.sh
```
2014-09-22 18:41:46 +00:00
Kill the proxy running in the background:
After you are done running this demo make sure to kill it:
```bash
$ jobs
[1]+ Running ./1-run-web-proxy.sh &
$ kill %1
[1]+ Terminated: 15 ./1-run-web-proxy.sh
```
### Image Copyright
Note that he images included here are public domain.
* [kitten](http://commons.wikimedia.org/wiki/File:Kitten-stare.jpg)
* [nautilus](http://commons.wikimedia.org/wiki/File:Nautilus_pompilius.jpg)