Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 66 additions & 39 deletions serving/samples/thumbnailer-go/README.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,57 @@
# Thumbnailer Demo
# Thumbnailer External Dependencies Demo

Thumbnailer demo is a walk-through example on how to deploy a 'dockerized' application to the Knative Serving service. In this demo we will use a sample `golang` application that takes video URL as an input and generates its thumbnail image.
This is a walk-through example that demonstrates deploying a dockerized
application that accesses external dependencies to Knative Serving. In this demo
we will use a sample `golang` application that takes a video URL as an input and
generates its thumbnail image using the `ffmpeg` framework.

> In this demo we will assume access to existing Knative Serving service. If not, consult [README.md](https://github.com/knative/serving/blob/master/README.md) on how to deploy one.
## Before you begin

## Sample Code
* [Install Knative Serving](../../../install/README.md)

In this demo we are going to use a simple `golang` REST app called [rester-tester](https://github.com/mchmarny/rester-tester). It's important to point out that this application doesn't use any 'special' Knative Serving components nor does it have any Knative Serving SDK dependencies.
If you want to test and run the app locally:
* [Install Go](https://golang.org/doc/install)
* [Download `ffmpeg`](https://www.ffmpeg.org/download.html)

### App code
## Sample code

Let's start by cloning the public `rester-tester` repository
In this demo we are going to use a simple `golang` REST app called
[rester-tester](https://github.com/mchmarny/rester-tester). It's important
to point out that this application doesn't use any special Knative Serving
components, nor does it have any Knative Serving SDK dependencies.

### Cloning the sample code

Let's start by cloning the public `rester-tester` repository:

```
git clone git@github.com:mchmarny/rester-tester.git
cd rester-tester
```

The `rester-tester` application uses [godep](https://github.com/tools/godep) to manage its own dependencies. Go get it and restore the app dependencies
The `rester-tester` application uses [godep](https://github.com/tools/godep)
to manage its own dependencies. Download `godep` and restore the app dependencies:

```
go get github.com/tools/godep
godep restore
```

### Test
### Run tests

To quickly make sure the application is ready, execute the integrated tests
To make sure the application is ready, run the integrated tests:

```
go test ./...
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this fail if I don't have ffmpeg installed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rewrote the "before you begin" section to include ffmpeg

```

### Run
### Run the app

You can now run the `rester-tester` application locally in `go` or using Docker
You can now run the `rester-tester` application locally in `go` or using Docker.

**Local**

> Note: to run the application locally in `go` you will need [FFmpeg](https://www.ffmpeg.org/) in your path.
To run the app:

```
go build
Expand All @@ -47,7 +60,10 @@ go build

**Docker**

When running the application locally in docker, you do not need to install `ffmpeg`, Docker will install it for you 'inside' of the Docker image
When running the application locally using Docker, you do not need to install `ffmpeg`;
Docker will install it for you 'inside' of the Docker image.

To run the app:

```
docker build -t rester-tester:latest .
Expand All @@ -56,31 +72,34 @@ docker run -p 8080:8080 rester-tester:latest

### Test

To test the thumbnailing service use `curl` to submit `src` video URL.
To test the thumbnailing service, use `curl` to submit the `src`, a video URL:

```
curl -X POST -H "Content-Type: application/json" http://localhost:8080/image \
-d '{"src":"https://www.youtube.com/watch?v=DjByja9ejTQ"}'
```

## Deploy (Prebuilt)
## Deploying the app to Knative

From this point, you can either deploy a prebuilt image of the app, or build
the app locally and then deploy it.

You can now deploy the `rester-tester` app to the Knative Serving service using `kubectl` using the included `sample-prebuilt.yaml`.
### Deploying a prebuilt image

You can deploy a prebuilt image of the `rester-tester` app to Knative Serving using
`kubectl` and the included `sample-prebuilt.yaml` file:

```
# From inside this directory
# From inside the thumbnailer-go directory
kubectl apply -f sample-prebuilt.yaml
```

If you would like to publish your own copy of the container image, you can update the image reference in this file.


## Deploy (with Build)
### Building and deploying a version of the app

You can also build the image as part of deployment. This sample uses the
If you want to build the image yourself, follow these instructions. This sample uses the
[Kaniko build
template](https://github.com/knative/build-templates/blob/master/kaniko/kaniko.yaml)
in the [build-templates](https://github.com/knative/build-templates/) repo.
from the [build-templates](https://github.com/knative/build-templates/) repo.

```shell
# Replace the token string with a suitable registry
Expand Down Expand Up @@ -109,63 +128,69 @@ items:
...
```

Once `BuildComplete` has a `status: "True"`, the revision will get deployed as in the "prebuilt" case above.
Once `BuildComplete` has a `status: "True"`, the revision will be deployed.


## Demo
## Using the app

To confirm that the app deployed, you can check for the Knative Serving service using `kubectl`. First, is there an ingress service:
To confirm that the app deployed, you can check for the Knative Serving service using `kubectl`.
First, is there an ingress service, and does it have an `EXTERNAL-IP`:

```
kubectl get svc knative-ingressgateway -n istio-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
knative-ingressgateway LoadBalancer 10.23.247.74 35.203.155.229 80:32380/TCP,443:32390/TCP,32400:32400/TCP 2d
```

Sometimes the newly deployed app may take few seconds to initialize. You can check its status like this
> Note: It can take a few seconds for the service to show an `EXTERNAL-IP`.

The newly deployed app may take few seconds to initialize. You can check its status
by entering the following command:

```
kubectl -n default get pods
```

The Knative Serving ingress service will automatically be assigned an IP so let's capture that IP so we can use it in subsequent `curl` commands
The Knative Serving ingress service will automatically be assigned an external IP,
so let's capture the IP and Host URL in variables so that we can use them
in `curl` commands:

```
# Put the Host name into an environment variable.
# Put the Host URL into an environment variable.
export SERVICE_HOST=`kubectl get route thumb -o jsonpath="{.status.domain}"`

# Put the ingress IP into an environment variable.
export SERVICE_IP=`kubectl get svc knative-ingressgateway -n istio-system -o jsonpath="{.status.loadBalancer.ingress[*].ip}"`
```

If your cluster is running outside a cloud provider (for example on Minikube),
your services will never get an external IP address. In that case, use the istio `hostIP` and `nodePort` as the service IP:
your services will never get an external IP address. In that case, use the istio
`hostIP` and `nodePort` as the service IP:

```shell
export SERVICE_IP=$(kubectl get po -l knative=ingressgateway -n istio-system -o 'jsonpath={.items[0].status.hostIP}'):$(kubectl get svc knative-ingressgateway -n istio-system -o 'jsonpath={.spec.ports[?(@.port==80)].nodePort}')
```

> To make the JSON service responses more readable consider installing [jq](https://stedolan.github.io/jq/), makes JSON pretty

### Ping

Let's start with a simple `ping` service
Let's start with a simple `ping` to make sure the app is deployed:

```
curl -H "Content-Type: application/json" -H "Host: $SERVICE_HOST" \
http://$SERVICE_IP/ping | jq '.'
http://$SERVICE_IP/ping
```

### Video Thumbnail

Now the video thumbnail.
Now, supply the video URL and generate a video thumbnail:

```
curl -X POST -H "Content-Type: application/json" -H "Host: $SERVICE_HOST" \
http://$SERVICE_IP/image -d '{"src":"https://www.youtube.com/watch?v=DjByja9ejTQ"}' | jq '.'
http://$SERVICE_IP/image -d '{"src":"https://www.youtube.com/watch?v=DjByja9ejTQ"}'
```

You can then download the newly created thumbnail. Make sure to replace the image name with the one returned by the previous service
You can then download the newly created thumbnail. Make sure to replace the
image file name with the one returned by the previous curl request:

```
curl -H "Host: $SERVICE_HOST" \
Expand All @@ -174,4 +199,6 @@ curl -H "Host: $SERVICE_HOST" \

## Final Thoughts

While we used in this demo an external application, the Knative Serving deployment steps would be similar for any 'dockerized' app you may already have... just copy the `thumbnailer.yaml` and change a few variables.
Although this demo uses an external application, the Knative Serving deployment
steps would be similar for any 'dockerized' app you may already have.
Just copy the `thumbnailer.yaml` and change a few variables.