From bd196ea49ccc17b4b3da3779f12d0c6b9737a5ce Mon Sep 17 00:00:00 2001 From: Max Forbes Date: Wed, 10 Sep 2014 13:56:56 -0700 Subject: [PATCH] Fix some readme and script bugs in examples (take 2). v2: Resolve issues from comments, fix bugs in update-demo example, rename files for clarity, add turn-down steps. v3: Add more set commands, clean up rest of env var checks. --- docs/getting-started-guides/gce.md | 2 +- examples/guestbook/README.md | 13 ++++++ .../build-images.sh => 0-build-images.sh} | 18 ++++---- ...{0-run-web-proxy.sh => 1-run-web-proxy.sh} | 7 ++++ ....sh => 2-create-replication-controller.sh} | 6 ++- .../update-demo/{2-scale.sh => 3-scale.sh} | 4 ++ ...-rolling-update.sh => 4-rolling-update.sh} | 6 ++- examples/update-demo/{4-down.sh => 5-down.sh} | 4 ++ examples/update-demo/README.md | 42 ++++++++++++------- examples/update-demo/local/index.html | 1 + examples/update-demo/local/script.js | 9 ++-- 11 files changed, 81 insertions(+), 31 deletions(-) rename examples/update-demo/{images/build-images.sh => 0-build-images.sh} (64%) rename examples/update-demo/{0-run-web-proxy.sh => 1-run-web-proxy.sh} (93%) rename examples/update-demo/{1-create-replication-controller.sh => 2-create-replication-controller.sh} (90%) rename examples/update-demo/{2-scale.sh => 3-scale.sh} (94%) rename examples/update-demo/{3-rolling-update.sh => 4-rolling-update.sh} (90%) rename examples/update-demo/{4-down.sh => 5-down.sh} (94%) diff --git a/docs/getting-started-guides/gce.md b/docs/getting-started-guides/gce.md index c0242a22065..fad62a35b24 100644 --- a/docs/getting-started-guides/gce.md +++ b/docs/getting-started-guides/gce.md @@ -6,7 +6,7 @@ [http://cloud.google.com/console](http://cloud.google.com/console) for more details. 2. Make sure you can start up a GCE VM. At least make sure you can do the [Create an instance](https://developers.google.com/compute/docs/quickstart#addvm) part of the GCE Quickstart. 3. Make sure you can ssh into the VM without interactive prompts. You'll need to set up a ssh key and expose port 22 in the firewall if you choose to use a network other than the default network (`gcutil addfirewall --description "SSH allowed from anywhere" --allowed=tcp:22 default-ssh`) -4. You need to have the Google Storage API, and the Google Storage JSON API enabled. +4. You need to have the Google Cloud Storage API, and the Google Cloud Storage JSON API enabled. 5. You must have Go (version 1.2 or later) installed: [www.golang.org](http://www.golang.org). 6. You must have the [`gcloud` components](https://developers.google.com/cloud/sdk/) installed. 7. Ensure that your `gcloud` components are up-to-date by running `gcloud components update`. diff --git a/examples/guestbook/README.md b/examples/guestbook/README.md index 8a1df634b78..7e11ffc2f6f 100644 --- a/examples/guestbook/README.md +++ b/examples/guestbook/README.md @@ -8,6 +8,11 @@ The example combines a web frontend, a redis master for storage and a replicated This example assumes that you have forked the repository and [turned up a Kubernetes cluster](https://github.com/GoogleCloudPlatform/kubernetes#contents): +```shell +$ cd kubernetes +$ hack/dev-build-and-up.sh +``` + ### Step One: Turn up the redis master. Use the file `examples/guestbook/redis-master.json` which describes a single pod running a redis key-value server in a container. @@ -307,3 +312,11 @@ For details about limiting traffic to specific sources, see the [gcutil document [cloud-console]: https://console.developer.google.com [gcutil-docs]: https://developers.google.com/compute/docs/gcutil/reference/firewall#addfirewall + +### Step Six: Cleanup + +To turn down a Kubernetes cluster: + +```shell +$ cluster/kube-down.sh +``` diff --git a/examples/update-demo/images/build-images.sh b/examples/update-demo/0-build-images.sh similarity index 64% rename from examples/update-demo/images/build-images.sh rename to examples/update-demo/0-build-images.sh index 25edd084a47..d6e7e946ca0 100755 --- a/examples/update-demo/images/build-images.sh +++ b/examples/update-demo/0-build-images.sh @@ -16,17 +16,19 @@ # This script will build and push the images necessary for the demo. -if (( $# != 1 )); then - echo "Usage: $0 " +set -o errexit +set -o nounset +set -o pipefail + +if [[ "${DOCKER_HUB_USER+set}" != "set" ]] ; then + echo "Please set DOCKER_HUB_USER to your Docker hub account" exit 1 fi -DOCKER_USER=$1 - set -x -docker build -t update-demo-base base -docker build -t $DOCKER_USER/update-demo:kitten kitten -docker build -t $DOCKER_USER/update-demo:nautilus nautilus +docker build -t update-demo-base images/base +docker build -t "${DOCKER_HUB_USER}/update-demo:kitten" images/kitten +docker build -t "${DOCKER_HUB_USER}/update-demo:nautilus" images/nautilus -docker push $DOCKER_USER/update-demo +docker push "${DOCKER_HUB_USER}/update-demo" diff --git a/examples/update-demo/0-run-web-proxy.sh b/examples/update-demo/1-run-web-proxy.sh similarity index 93% rename from examples/update-demo/0-run-web-proxy.sh rename to examples/update-demo/1-run-web-proxy.sh index 2a26ae765c5..f51295c84f3 100755 --- a/examples/update-demo/0-run-web-proxy.sh +++ b/examples/update-demo/1-run-web-proxy.sh @@ -14,9 +14,16 @@ # See the License for the specific language governing permissions and # limitations under the License. +set -o errexit +set -o nounset +set -o pipefail + echo "Running local proxy to Kubernetes API Server. Run this in a " echo "separate terminal or run it in the background." echo echo " http://localhost:8001/static/" echo + +set -x + ../../cluster/kubecfg.sh -proxy -www local/ diff --git a/examples/update-demo/1-create-replication-controller.sh b/examples/update-demo/2-create-replication-controller.sh similarity index 90% rename from examples/update-demo/1-create-replication-controller.sh rename to examples/update-demo/2-create-replication-controller.sh index 450e57e1a0d..7b032d8cd5b 100755 --- a/examples/update-demo/1-create-replication-controller.sh +++ b/examples/update-demo/2-create-replication-controller.sh @@ -14,7 +14,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -if [ -z "$DOCKER_HUB_USER" ] ; then +set -o errexit +set -o nounset +set -o pipefail + +if [[ "${DOCKER_HUB_USER+set}" != "set" ]] ; then echo "Please set DOCKER_HUB_USER to your Docker hub account" exit 1 fi diff --git a/examples/update-demo/2-scale.sh b/examples/update-demo/3-scale.sh similarity index 94% rename from examples/update-demo/2-scale.sh rename to examples/update-demo/3-scale.sh index f19e53bb57b..e7cc5ae6f24 100755 --- a/examples/update-demo/2-scale.sh +++ b/examples/update-demo/3-scale.sh @@ -14,6 +14,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +set -o errexit +set -o nounset +set -o pipefail + NEW_SIZE=${1:-4} export KUBE_REPO_ROOT=${KUBE_REPO_ROOT-$(dirname $0)/../..} diff --git a/examples/update-demo/3-rolling-update.sh b/examples/update-demo/4-rolling-update.sh similarity index 90% rename from examples/update-demo/3-rolling-update.sh rename to examples/update-demo/4-rolling-update.sh index 2aade212f0e..03c5e75c54d 100755 --- a/examples/update-demo/3-rolling-update.sh +++ b/examples/update-demo/4-rolling-update.sh @@ -14,7 +14,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -if [ -z "$DOCKER_HUB_USER" ] ; then +set -o errexit +set -o nounset +set -o pipefail + +if [[ "${DOCKER_HUB_USER+set}" != "set" ]] ; then echo "Please set DOCKER_HUB_USER to your Docker hub account" exit 1 fi diff --git a/examples/update-demo/4-down.sh b/examples/update-demo/5-down.sh similarity index 94% rename from examples/update-demo/4-down.sh rename to examples/update-demo/5-down.sh index 747aafa0d42..0167bce3f1c 100755 --- a/examples/update-demo/4-down.sh +++ b/examples/update-demo/5-down.sh @@ -14,6 +14,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +set -o errexit +set -o nounset +set -o pipefail + export KUBE_REPO_ROOT=${KUBE_REPO_ROOT-$(dirname $0)/../..} export KUBECFG=${KUBECFG-$KUBE_REPO_ROOT/cluster/kubecfg.sh} diff --git a/examples/update-demo/README.md b/examples/update-demo/README.md index 8baf41e6643..519cae44244 100644 --- a/examples/update-demo/README.md +++ b/examples/update-demo/README.md @@ -19,11 +19,12 @@ This example demonstrates the usage of Kubernetes to perform a live update on a ### Step Zero: Prerequisites -This example assumes that you have forked the repository and [turned up a Kubernetes cluster](https://github.com/GoogleCloudPlatform/kubernetes-new#setup): +This example assumes that you have forked the repository and [turned up a Kubernetes cluster](https://github.com/GoogleCloudPlatform/kubernetes-new#contents): - $ cd kubernetes - $ hack/dev-build-and-up.sh - $ hack/build-go.sh +```shell +$ cd kubernetes +$ hack/dev-build-and-up.sh +``` This example also assumes that you have [Docker](http://docker.io) installed on your local machine. @@ -35,47 +36,47 @@ You may need to open the firewall for port 8080 using the [console][cloud-consol $ gcutil addfirewall --allowed=tcp:8080 --target_tags=kubernetes-minion kubernetes-minion-8080 ``` -### Step One: Build the image +### Step Zero: Build the image ```shell -$ cd kubernetes/examples/update-demo -$ ./build-images.sh +$ cd examples/update-demo +$ ./0-build-images.sh ``` -### Step Two: Turn up the UX for the demo +### Step One: Turn up the UX for the demo ```shell -$ ./0-run-web-proxy.sh & +$ ./1-run-web-proxy.sh & ``` This can sometimes spew to the output so you could also run it in a different terminal. Now visit the the [demo website](http://localhost:8001/static). You won't see anything much quite yet. -### Step Three: Run the controller +### 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 ```shell -$ ./1-create-replication-controller.sh +$ ./2-create-replication-controller.sh ``` After these pull the image (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 Four: Try resizing the controller +### Step Three: Try resizing the controller Now we will increase the number of replicas from two to four: ```shell -$ ./2-scale.sh +$ ./3-scale.sh ``` 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 Five: Update the docker image +### 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. ```shell -$ ./3-rolling-update +$ ./4-rolling-update ``` The rollingUpdate command in kubecfg will do 2 things: @@ -87,13 +88,22 @@ Watch the UX, it will update one pod every 10 seconds until all of the pods have ### Step Five: Bring down the pods ```shell -$ ./4-down.sh +$ ./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. [cloud-console]: https://console.developer.google.com +### Step Six: Cleanup + +To turn down a Kubernetes cluster: + +```shell +$ cd ../.. # Up to kubernetes. +$ cluster/kube-down.sh +``` + ### Image Copyright Note that he images included here are public domain. diff --git a/examples/update-demo/local/index.html b/examples/update-demo/local/index.html index 0b66f8488db..07a3a8395ef 100644 --- a/examples/update-demo/local/index.html +++ b/examples/update-demo/local/index.html @@ -25,6 +25,7 @@ limitations under the License. ID: {{server.id}}
Host: {{server.host}}
+ Status: {{server.status}}
Image: {{server.dockerImage}}
Labels: