Skip to content

Commit

Permalink
Rewrite guestbook example to use kube-dns instead of host:port
Browse files Browse the repository at this point in the history
This fixes #5091
  • Loading branch information
piosz committed Mar 11, 2015
1 parent 6d465c4 commit 4679a37
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 65 deletions.
82 changes: 34 additions & 48 deletions examples/guestbook/README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/guestbook/frontend-controller.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"id": "frontend",
"containers": [{
"name": "php-redis",
"image": "kubernetes/example-guestbook-php-redis",
"image": "kubernetes/example-guestbook-php-redis:v2",
"cpu": 100,
"memory": 50000000,
"ports": [{"name": "http-server", "containerPort": 80}]
Expand Down
14 changes: 5 additions & 9 deletions examples/guestbook/php-redis/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,17 @@
if ($_GET['cmd'] == 'set') {
$client = new Predis\Client([
'scheme' => 'tcp',
'host' => getenv('REDIS_MASTER_SERVICE_HOST') ?: getenv('SERVICE_HOST'),
'port' => getenv('REDIS_MASTER_SERVICE_PORT'),
'host' => 'redis-master',
'port' => 6379,
]);

$client->set($_GET['key'], $_GET['value']);
print('{"message": "Updated"}');
} else {
$read_port = getenv('REDIS_MASTER_SERVICE_PORT');

if (isset($_ENV['REDISSLAVE_SERVICE_PORT'])) {
$read_port = getenv('REDISSLAVE_SERVICE_PORT');
}
$client = new Predis\Client([
'scheme' => 'tcp',
'host' => getenv('REDIS_MASTER_SERVICE_HOST') ?: getenv('SERVICE_HOST'),
'port' => $read_port,
'host' => 'redis-slave',
'port' => 6379,
]);

$value = $client->get($_GET['key']);
Expand Down
2 changes: 1 addition & 1 deletion examples/guestbook/redis-slave-controller.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"id": "redis-slave",
"containers": [{
"name": "redis-slave",
"image": "brendanburns/redis-slave",
"image": "kubernetes/redis-slave:v2",
"cpu": 200,
"ports": [{"containerPort": 6379}]
}]
Expand Down
2 changes: 1 addition & 1 deletion examples/guestbook/redis-slave-service.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id": "redisslave",
"id": "redis-slave",
"kind": "Service",
"apiVersion": "v1beta1",
"port": 6379,
Expand Down
2 changes: 1 addition & 1 deletion examples/guestbook/redis-slave/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

redis-server --slaveof ${REDIS_MASTER_SERVICE_HOST:-$SERVICE_HOST} $REDIS_MASTER_SERVICE_PORT
redis-server --slaveof redis-master 6379
6 changes: 3 additions & 3 deletions hack/test-cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -419,13 +419,13 @@ __EOF__
kubectl create -f examples/guestbook/redis-master-service.json "${kube_flags[@]}"
kubectl create -f examples/guestbook/redis-slave-service.json "${kube_flags[@]}"
# Post-condition: redis-master and redis-slave services are running
kube::test::get_object_assert services "{{range.items}}{{.$id_field}}:{{end}}" 'kubernetes:kubernetes-ro:redis-master:redisslave:'
kube::test::get_object_assert services "{{range.items}}{{.$id_field}}:{{end}}" 'kubernetes:kubernetes-ro:redis-master:redis-slave:'

### Delete multiple services at once
# Pre-condition: redis-master and redis-slave services are running
kube::test::get_object_assert services "{{range.items}}{{.$id_field}}:{{end}}" 'kubernetes:kubernetes-ro:redis-master:redisslave:'
kube::test::get_object_assert services "{{range.items}}{{.$id_field}}:{{end}}" 'kubernetes:kubernetes-ro:redis-master:redis-slave:'
# Command
kubectl delete services redis-master redisslave "${kube_flags[@]}" # delete multiple services at once
kubectl delete services redis-master redis-slave "${kube_flags[@]}" # delete multiple services at once
# Post-condition: Only the default kubernetes services are running
kube::test::get_object_assert services "{{range.items}}{{.$id_field}}:{{end}}" 'kubernetes:kubernetes-ro:'

Expand Down
2 changes: 1 addition & 1 deletion pkg/kubectl/cmd/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func TestDeleteDirectory(t *testing.T) {
cmd.Flags().Set("filename", "../../../examples/guestbook")
cmd.Run(cmd, []string{})

if buf.String() != "frontend-controller\nfrontend\nredis-master-controller\nredis-master\nredis-slave-controller\nredisslave\n" {
if buf.String() != "frontend-controller\nfrontend\nredis-master-controller\nredis-master\nredis-slave-controller\nredis-slave\n" {
t.Errorf("unexpected output: %s", buf.String())
}
}
Expand Down

12 comments on commit 4679a37

@pires
Copy link
Contributor

@pires pires commented on 4679a37 Mar 28, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very interesting, but you're just breaking a lot of getting-started guides like Atomic, which don't use DNS yet.

@piosz
Copy link
Member Author

@piosz piosz commented on 4679a37 Mar 30, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you point me to the getting-started Atomic guide? I can't see any.

I see the problem, but there is no better solution (or at least I can't see any). Did you have a chance to taka a look into #5091?

@pires
Copy link
Contributor

@pires pires commented on 4679a37 Mar 30, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@piosz
Copy link
Member Author

@piosz piosz commented on 4679a37 Mar 30, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the link. How big is an effort to start supporting DNS in Atomic? We have kube-dns service which can be probably run on Atomic.

@pires
Copy link
Contributor

@pires pires commented on 4679a37 Mar 30, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not related to that project. Just mentioned it as an example and because someone was complaining about it in #google-containers @ irc.freenode.net.

@piosz
Copy link
Member Author

@piosz piosz commented on 4679a37 Mar 30, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Thanks!

@nzwulfin
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can go ahead and add some kube-dns details to the Atomic getting started guide, but I'm looking through the various different guides in the repository and don't see any that have details on setting up kube-dns as a prerequisite.

Can we add what a working "kubernetes cluster" in Step Zero consist of for this example? This could help make sure that the cluster based getting started guides can consistently run the guestbook.

@piosz
Copy link
Member Author

@piosz piosz commented on 4679a37 Apr 8, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@erictune could you please answer for @nzwulfin's question?

@roman-shuhov
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@piosz how did you enable dns in this example? As I see you switched to v2 docker images, but not sure where kube-dns is configured.

@piosz
Copy link
Member Author

@piosz piosz commented on 4679a37 Apr 13, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kube-dns is a service (see https://github.com/GoogleCloudPlatform/kubernetes/tree/master/cluster/addons/dns). It is enabled by default for example on GCE. I changed this example to use dns instead of HOST, PORT env vars, for example instead of using REDIS_MASTER_SERVICE_HOST as an address of redis master, I use just redis-master which will be resolved to the redis host by kube-dns.

@roman-shuhov
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as i understood, guestbook is a generic example. Is kube-dns enabled by default on amazon, openstack, etc?

@piosz
Copy link
Member Author

@piosz piosz commented on 4679a37 Apr 13, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, you can ask on IRC channel.

Please sign in to comment.