Use ambassador to talk to the frontend ui (#71)

* Create a ksonnet app component to deploy to k8s
This commit is contained in:
Ankush Agarwal 2018-04-06 21:50:08 -07:00 committed by k8s-ci-robot
parent 9f6ccde03f
commit d01d8435bf
17 changed files with 85 additions and 19 deletions

View File

@ -1,3 +1,3 @@
FROM gcr.io/kubeflow-images-staging/tensorflow-1.6.0-notebook-cpu
COPY tf-job/train.py /workdir/train.py
COPY train.py /workdir/train.py
COPY seq2seq_utils.py /workdir/seq2seq_utils.py

View File

@ -8,6 +8,9 @@
// Each object below should correspond to a component in the components/ directory
tfjob: {
},
ui: {
},
},
}

View File

@ -0,0 +1,7 @@
local env = std.extVar("__ksonnet/environments");
local params = std.extVar("__ksonnet/params").components.ui;
local k = import "k.libsonnet";
local ui = import "ui.libsonnet";
std.prune(k.core.v1.list.new(ui.parts(params, env)))

View File

@ -0,0 +1,58 @@
{
parts(params, env):: [
{
apiVersion: "v1",
kind: "Service",
metadata: {
name: "issue-summarization-ui",
namespace: env.namespace,
annotations: {
"getambassador.io/config": "---\napiVersion: ambassador/v0\nkind: Mapping\nname: issue_summarization_ui\nprefix: /issue-summarization/\nrewrite: /\nservice: issue-summarization-ui:80\n",
},
},
spec: {
ports: [
{
port: 80,
targetPort: 80,
},
],
selector: {
app: "issue-summarization-ui",
},
type: "ClusterIP",
},
},
{
apiVersion: "apps/v1beta1",
kind: "Deployment",
metadata: {
name: "issue-summarization-ui",
namespace: env.namespace,
},
spec: {
replicas: 1,
template: {
metadata: {
labels: {
app: "issue-summarization-ui",
},
},
spec: {
containers: [
{
image: "gcr.io/kubeflow-images-staging/issue-summarization-ui:latest",
name: "issue-summarization-ui",
ports: [
{
containerPort: 80,
},
],
},
],
},
},
},
},
],
}

View File

@ -34,34 +34,32 @@ gcloud docker -- push gcr.io/gcr-repository-name/issue-summarization-ui:0.1
## Deploy the frontend image to your kubernetes cluster
To serve the frontend interface, run the image using the following command:
[notebooks](notebooks) contains a ksonnet app([ks-app](notebooks/ks-app)). The ui component in the ks-app contains the frontend image deployment.
```
ks generate deployed-service issue-summarization-ui \
--image gcr.io/gcr-repository-name/issue-summarization-ui:0.1 \
--type ClusterIP
ks param set issue-summarization-ui namespace $NAMESPACE
ks apply cloud -n $NAMESPACE -c issue-summarization-ui
Create an environment to deploy the ksonnet app
```commandline
cd notebooks/ks-app
ks env add frontendenv --namespace ${NAMESPACE}
```
TODO: Figure out why deployed-service prototype does not pick up the
namespace parameter. The workaround is to generate the yaml for
issue-summarization-ui service and deployment objects, inserting
the namespace parameter, and applying manually to the cluster.
To serve the frontend interface, apply the ui component of the ksonnet app:
```
ks apply frontendenv -c ui
```
## View results from the frontend
To setup a proxy to the UI port running in k8s, issue the following command:
We use ambassador to route requests to the frontend. You can port-forward the ambassador container locally:
```
kubectl port-forward $(kubectl get pods -n ${NAMESPACE} -l app=issue-summarization-ui -o jsonpath='{.items[0].metadata.name}') -n ${NAMESPACE} 8081:80
kubectl port-forward $(kubectl get pods -n ${NAMESPACE} -l service=ambassador -o jsonpath='{.items[0].metadata.name}') -n ${NAMESPACE} 8080:80
```
In a browser, navigate to `http://localhost:8081`, where you will be greeted by "Issue
In a browser, navigate to `http://localhost:8080/issue-summarization/`, where you will be greeted by "Issue
text" Enter text into the input box and click submit. You should see a
summary that was provided by your trained model.
Next: [Teardown](teardown.md)

View File

@ -6,7 +6,7 @@ back to GCS.
## Create the image for training
The [tf-job](notebooks/tf-job) directory contains the necessary files to create a image for training. The [train.py](notebooks/tf-job/train.py) file contains the training code. Here is how you can create an image and push it to gcr.
The [notebooks](notebooks) directory contains the necessary files to create a image for training. The [train.py](notebooks/train.py) file contains the training code. Here is how you can create an image and push it to gcr.
```commandline
cd notebooks/
@ -41,12 +41,12 @@ kubectl --namespace=${NAMESPACE} create secret generic gcp-credentials --from-fi
## Run the TFJob using your image
[tf-job](notebooks/tf-job) contains a ksonnet app([ks-app](notebooks/tf-job/ks-app)) to deploy the TFJob.
[notebooks](notebooks) contains a ksonnet app([ks-app](notebooks/ks-app)) to deploy the TFJob.
Create an environment to deploy the ksonnet app
```commandline
cd notebooks/tf-job/ks-app
cd notebooks/ks-app
ks env add tfjob --namespace ${NAMESPACE}
```