Skip to content

Commit

Permalink
Move both guestbook variants under a common directory
Browse files Browse the repository at this point in the history
  • Loading branch information
joeduffy committed Sep 1, 2018
1 parent 3a23584 commit 011cf03
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 71 deletions.
81 changes: 12 additions & 69 deletions kubernetes-ts-guestbook/README.md
Original file line number Diff line number Diff line change
@@ -1,74 +1,17 @@
# Kubernetes Guestbook
# Kubernetes Guestbook (Two Ways)

A version of the [Kubernetes Guestbook](https://kubernetes.io/docs/tutorials/stateless-application/guestbook/)
application using Pulumi.
A port of the standard [Kubernetes Guestbook](https://kubernetes.io/docs/tutorials/stateless-application/guestbook/)
to Pulumi. This example shows you how to build and deploy a simple, multi-tier web application using Kubernetes and
Docker, and consists of three components:

This is a straight port of the original YAML, and doesn't highlight advantages of using real languages. For an example
using abstraction to cut down on boilerplate, please see the [easy Guestbook variant](../kubernetes-ts-guestbook-easy),
also in this repo. It provisions the same set of resources.
* A single-instance Redis master to store guestbook entries
* Multiple replicated Redis instances to serve reads
* Multiple web frontend instances

## Running the App
In this directory, you will find two variants of the Guestbook:

Follow the steps in [Pulumi Installation and Setup](https://pulumi.io/install/) and [Configuring Pulumi
Kubernetes](https://pulumi.io/reference/kubernetes.html#configuration) to get setup with Pulumi and Kubernetes.
1. [simple/](./simple) is a straight port of the original YAML.
2. [components](./components) demonstrates benefits of using a real language, namely eliminating boilerplate through
the use of real component abstractions.

Install dependencies:

```sh
npm install
```

Create a new stack:

```sh
$ pulumi stack init
Enter a stack name: testbook
```

This example will attempt to expose the Guestbook application to the Internet with a `Service` of
type `LoadBalancer`. Since minikube does not support `LoadBalancer`, the Guestbook application
already knows to use type `ClusterIP` instead; all you need to do is to tell it whether you're
deploying to minikube:

```sh
pulumi config set guestbook:isMinikube <value>
```

Perform the deployment:

```sh
$ pulumi up
Updating stack 'testbook'
Performing changes:

Type Name Status Info
+ pulumi:pulumi:Stack guestbook-testbook created
+ ├─ kubernetes:apps:Deployment redis-master created
+ ├─ kubernetes:apps:Deployment frontend created
+ ├─ kubernetes:apps:Deployment redis-slave created
+ ├─ kubernetes:core:Service redis-master created 1 info message
+ ├─ kubernetes:core:Service redis-slave created 1 info message
+ └─ kubernetes:core:Service frontend created 2 info messages

---outputs:---
frontendIp: "35.232.147.18"

info: 7 changes performed:
+ 7 resources created
Update duration: 40.829381902s

Permalink: https://app.pulumi.com/hausdorff/testbook/updates/1
```

And finally - open the application in your browser to see the running application. If you're running
macOS you can simply run:

```sh
open $(pulumi stack output frontendIp)
```

> *Note*: minikube does not support type `LoadBalancer`; if you are deploying to minikube, make sure
> to run `kubectl port-forward svc/frontend 8080:80` to forward the cluster port to the local
> machine and access the service via `localhost:8080`.
![Guestbook in browser](./imgs/guestbook.png)
Both examples provision the exact same Kubernetes Guestbook application, but showcase different aspects of Pulumi.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Kubernetes Guestbook (Easy Variant)
# Kubernetes Guestbook (with Components)

A version of the [Kubernetes Guestbook](https://kubernetes.io/docs/tutorials/stateless-application/guestbook/)
application using Pulumi. Unlike [the straight port of the original YAML](../kubernetes-ts-guestbook), this variant
application using Pulumi. Unlike [the straight port of the original YAML](../simple), this variant
leverages real code to eliminate boilerplate. A `ServiceDeployment` class is used that combines the common pattern
of deploying a container image using a Kubernetes `Deployment`, and then scaling it using a `Service`.

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
74 changes: 74 additions & 0 deletions kubernetes-ts-guestbook/simple/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Kubernetes Guestbook (Simple Variant)

A version of the [Kubernetes Guestbook](https://kubernetes.io/docs/tutorials/stateless-application/guestbook/)
application using Pulumi.

This is a straight port of the original YAML, and doesn't highlight advantages of using real languages. For an example
using abstraction to cut down on boilerplate, please see the [variant using components](../components),
also in this repo. It provisions the same set of resources.

## Running the App

Follow the steps in [Pulumi Installation and Setup](https://pulumi.io/install/) and [Configuring Pulumi
Kubernetes](https://pulumi.io/reference/kubernetes.html#configuration) to get setup with Pulumi and Kubernetes.

Install dependencies:

```sh
npm install
```

Create a new stack:

```sh
$ pulumi stack init
Enter a stack name: testbook
```

This example will attempt to expose the Guestbook application to the Internet with a `Service` of
type `LoadBalancer`. Since minikube does not support `LoadBalancer`, the Guestbook application
already knows to use type `ClusterIP` instead; all you need to do is to tell it whether you're
deploying to minikube:

```sh
pulumi config set guestbook:isMinikube <value>
```

Perform the deployment:

```sh
$ pulumi up
Updating stack 'testbook'
Performing changes:

Type Name Status Info
+ pulumi:pulumi:Stack guestbook-testbook created
+ ├─ kubernetes:apps:Deployment redis-master created
+ ├─ kubernetes:apps:Deployment frontend created
+ ├─ kubernetes:apps:Deployment redis-slave created
+ ├─ kubernetes:core:Service redis-master created 1 info message
+ ├─ kubernetes:core:Service redis-slave created 1 info message
+ └─ kubernetes:core:Service frontend created 2 info messages

---outputs:---
frontendIp: "35.232.147.18"

info: 7 changes performed:
+ 7 resources created
Update duration: 40.829381902s

Permalink: https://app.pulumi.com/hausdorff/testbook/updates/1
```

And finally - open the application in your browser to see the running application. If you're running
macOS you can simply run:

```sh
open $(pulumi stack output frontendIp)
```

> *Note*: minikube does not support type `LoadBalancer`; if you are deploying to minikube, make sure
> to run `kubectl port-forward svc/frontend 8080:80` to forward the cluster port to the local
> machine and access the service via `localhost:8080`.
![Guestbook in browser](./imgs/guestbook.png)
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 011cf03

Please sign in to comment.