Skip to content

Commit c897798

Browse files
committed
Cleaning/Updating k8petstore dev tooling and build fixing, moving webserver to
main.go. Replacing vagrant tooling with docker-machine.
1 parent 8e25b7c commit c897798

File tree

11 files changed

+126
-193
lines changed

11 files changed

+126
-193
lines changed

examples/k8petstore/README.md

+32-9
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,31 @@ For a list of those images, see the `build-and-push` shell script - it builds an
6969

7070
modify the dockerhub user name in it accordingly.
7171

72-
## Get started with the WEBAPP
72+
## Hacking, extending, and locally testing on the k8petstore
7373

7474
The web app is written in Go, and borrowed from the original Guestbook example by brendan burns.
7575

76+
K8petstore is built to be expanded, and aims to attract developers interested in building and maintaining a polyglot, non-trivial kubernetes app as a community.
77+
78+
It can be a simple way to get started with kuberentes or golang application development.
79+
80+
Thus we've tried to make it easy to hack on, even without kubernetes. Just run the containers and glue them together using docker IP addresses !
81+
7682
We have extended it to do some error reporting, persisting of JSON petstore transactions (not much different then guestbook entries),
7783

7884
and supporting of additional REST calls, like LLEN, which returns the total # of transactions in the database.
7985

80-
To work on the app, just cd to the `dev` directory, and follow the instructions. You can easily edit it in your local machine, by installing
86+
If that is all working, you can finally run `k8petstore.sh` in any Kubernetes cluster, and run the app at scale.
87+
88+
### MAC USERS
8189

82-
redis and go. Then you can use the `Vagrantfile` in this top level directory to launch a minimal version of the app in pure docker containers.
90+
To develop against k8petstore, simply run the docker-machine-dev.sh script, which is built for mac users.
8391

84-
If that is all working, you can finally run `k8petstore.sh` in any Kubernetes cluster, and run the app at scale.
92+
### LINUX USERS
93+
94+
For now, modify the docker-machine-dev.sh script as necessary to use the provider of your choice. Most linux/docker users are savvy enough to do this easily.
95+
96+
If you need help, just ask on the mailing list.
8597

8698
## Set up the data generator (optional)
8799

@@ -125,23 +137,34 @@ You might want to change it to point to your customized Go image, if you chose t
125137

126138
So, to run this app in Kubernetes, simply run [The all in one k8petstore.sh shell script](k8petstore.sh).
127139

128-
Note that at the top of the script there are a few self explanatory parameters to set, among which the Public IPs parameter is where you can checkout the web ui (at $PUBLIC_IP:3000), which will show a plot and read outs of transaction throughput.
140+
## Should we use PublicIP, NodePort, Cloud loadbalancers ?
129141

130-
In the mean time, because the public IP will be deprecated in Kubernetes v1, we provide other 2 scripts k8petstore-loadbalancer.sh and k8petstore-nodeport.sh. As the names suggest, they rely on LoadBalancer and NodePort respectively. More details can be found [here](../../docs/user-guide/services.md#external-services).
142+
The original k8petstore used PUBLIC_IP fields to bind the web app to an IP.
143+
144+
However... because the public IP was deprecated in Kubernetes v1, we provide other 2 scripts k8petstore-loadbalancer.sh and k8petstore-nodeport.sh. As the names suggest, they rely on LoadBalancer and NodePort respectively. More details can be found [here](../../docs/user-guide/services.md#external-services).
145+
146+
We will continue to try to update k8petstore to use the idiomatic networking tools that kubernetes supports, if we fall behind, please create an issue !
131147

132148
## Future
133149

134-
In the future, we plan to add cassandra support. Redis is a fabulous in memory data store, but it is not meant for truly available and resilient storage.
150+
Future development ideas include, adding a persistent k/v store like cassandra/hbase/..., using kafka/activeMQ for the data sink (with redis as a consumer).
151+
152+
Additionally, adding analytics and meaningful streaming queries to the richly patterned data would also be interesting.
153+
154+
We are open to other ways of expanding the coverage and realism of the k8petstore application.
135155

136-
Thus we plan to add another tier of queueing, which empties the REDIS transactions into a cassandra store which persists.
156+
Reach out with ideas, pull requests, and so on!
157+
158+
The end goal is to support polyglot, real world, data-intensive application on kuberenetes which can be used both to learn how to maintain kubernetes applications
159+
160+
as well as for scale and functionality testing.
137161

138162
## Questions
139163

140164
For questions on running this app, you can ask on [Slack](../../docs/troubleshooting.md#slack).
141165

142166
For questions about bigpetstore, and how the data is generated, ask on the apache bigtop mailing list.
143167

144-
145168
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
146169
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/examples/k8petstore/README.md?pixel)]()
147170
<!-- END MUNGE: GENERATED_ANALYTICS -->

examples/k8petstore/Vagrantfile

-37
This file was deleted.

examples/k8petstore/build-push-containers.sh

+3
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ docker push jayunit100/k8-petstore-redis:$version
2727
docker push jayunit100/k8-petstore-redis-master:$version
2828
docker push jayunit100/k8-petstore-redis-slave:$version
2929
docker push jayunit100/k8-petstore-web-server:$version
30+
31+
### Now, start the application.
32+

examples/k8petstore/dev/README

-35
This file was deleted.

examples/k8petstore/dev/Vagrantfile

-44
This file was deleted.

examples/k8petstore/dev/hosts/Vagrantfile

-11
This file was deleted.

examples/k8petstore/dev/test.sh

-47
This file was deleted.
+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/bash
2+
3+
# Copyright 2015 The Kubernetes Authors All rights reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
!/bin/bash
18+
19+
function setup_vm() {
20+
### Provider = vbox. You can use another one if you want... But untested.
21+
PROVIDER=virtualbox
22+
23+
### Create a VM specific to this app...
24+
if docker-machine ls |grep -q k8petstore ; then
25+
echo "VM already exists, moving on..."
26+
else
27+
docker-machine create --driver $PROVIDER k8petstore
28+
fi
29+
}
30+
31+
function setup_docker() {
32+
33+
## Set the docker server, and then clean all containers...
34+
eval "$(docker-machine env k8petstore)"
35+
docker rm -f `docker ps -a -q`
36+
37+
### Now capture the IP.
38+
MACHINE_IP="`docker-machine ip k8petstore`"
39+
40+
}
41+
42+
function build_containers() {
43+
44+
version="`date +"%m-%d-%Y-%s"`"
45+
pushd ../redis
46+
docker build -t jayunit100/k8-petstore-redis:$version ./
47+
popd
48+
49+
pushd ../redis-master
50+
docker build -t jayunit100/k8-petstore-redis-master:$version ./
51+
popd
52+
53+
pushd ../redis-slave
54+
docker build -t jayunit100/k8-petstore-redis-slave:$version ./
55+
popd
56+
57+
pushd ../web-server
58+
docker build -t jayunit100/k8-petstore-web-server:$version ./
59+
popd
60+
}
61+
62+
function runk8petstore() {
63+
64+
### Finally, run the application.
65+
### This app is gauranteed to be a clean run using all the source.
66+
### You can use it to iteratively test/deploy k8petstore and make new changes.
67+
68+
### TODO, add slaves.
69+
70+
echo "Running k8petstore now..."
71+
docker run -d -p 6379:6379 jayunit100/k8-petstore-redis-master:$version
72+
docker run -d -e REDISMASTER_SERVICE_HOST=$MACHINE_IP -e REDISMASTER_SERVICE_PORT=6379 -p 3000:3000 jayunit100/k8-petstore-web-server:$version
73+
74+
}
75+
76+
setup_vm
77+
78+
setup_docker
79+
80+
build_containers
81+
82+
runk8petstore
+8-9
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
FROM google/golang:latest
1+
FROM golang:latest
22

33
# Add source to gopath. This is defacto required for go apps.
4-
ADD ./src /gopath/src/
4+
ADD ./src /gopath/src/k8petstore
5+
RUN mkdir /gopath/bin/
56
ADD ./static /tmp/static
67
ADD ./test.sh /opt/test.sh
78
RUN chmod 777 /opt/test.sh
8-
# $GOPATH/[src/a/b/c]
9-
# go build a/b/c
10-
# go run main
119

1210
# So that we can easily run and install
13-
WORKDIR /gopath/src/
11+
WORKDIR /gopath/src
1412

1513
# Install the code (the executables are in the main dir) This will get the deps also.
16-
RUN go get main
17-
#RUN go build main
14+
RUN export GOPATH=/gopath/ && go get k8petstore
15+
RUN export GOPATH=/gopath/ && go install k8petstore
16+
1817

1918
# Expected that you will override this in production kubernetes.
2019
ENV STATIC_FILES /tmp/static
21-
CMD /gopath/bin/main
20+
CMD /gopath/bin/k8petstore

hack/lib/golang.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ kube::golang::test_targets() {
7070
cmd/genconversion
7171
cmd/gendeepcopy
7272
cmd/genswaggertypedocs
73-
examples/k8petstore/web-server
73+
examples/k8petstore/web-server/src
7474
github.com/onsi/ginkgo/ginkgo
7575
test/e2e/e2e.test
7676
)

0 commit comments

Comments
 (0)