Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing language in the source to url sample #189

Merged
merged 5 commits into from
Jul 22, 2018
Merged
Changes from 1 commit
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
200 changes: 98 additions & 102 deletions serving/samples/source-to-url-go/README.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,46 @@
# Source to URL - Go
# Orchestrating a source-to-URL deployement on Kubernetes
Copy link
Member

Choose a reason for hiding this comment

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

typo


A sample that shows how to use Knative to go from source code in a git
repository to a running application with a URL. This sample uses Go.
A Go sample that shows how to use Knative to go from source code in a git
repository to a running application with a URL.

This sample uses the [Build](../../../build/README.md) and [Serving](../../README.md)
components of Knative to orchestrate an end-to-end deployment.

## Prerequisites

You need:

* A Kubernetes cluster with Knative installed. Follow the
[installation instructions](https://github.com/knative/docs/blob/master/install/README.md) if you need
to create one.
* Go installed and configured (optional, if you want to run the sample app
locally).
* Go installed and configured. This is optional, if you want to run the sample app
Copy link
Member

Choose a reason for hiding this comment

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

This is optional, and is only required if ...

locally.

## Configuring Knative

To use this sample, a few configuration steps are required before we can deploy.
You need to install a [Build Template](https://github.com/knative/build-templates)
that will be used by the sample, and register a secret for your container
registry. In this example, we'll use Docker Hub.
To use this sample, you need to install a build template and register a secret for Docker Hub.
Copy link
Member

Choose a reason for hiding this comment

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

Does this need to be Docker Hub, and not e.g. gcr.io?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rgregg Ryan, do you know?

Copy link
Contributor

Choose a reason for hiding this comment

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

For the samples in general, we've been using Docker Hub because it's agnostic of any of the Knative authors. We got good community feedback that we shouldn't use GCR all the time.


### Install kaniko build template
### Install the kaniko build template

This sample leverages the [kaniko build template](https://github.com/knative/build-templates/tree/master/kaniko)
to perform a source-to-container build on the Kubernetes cluster.
to perform a source-to-container build on your Kubernetes cluster.

To install the kaniko build template, we'll use kubectl to install the kaniko
manifest:
Use kubectl to install the kaniko manifest:

```shell
kubectl apply -f https://raw.githubusercontent.com/knative/build-templates/master/kaniko/kaniko.yaml
```

### Register secrets for Docker Hub

In order to push the container built from source to Docker Hub, we need to
register a secret in Kubernetes for authentication with Docker Hub.
In order to push the container that is built from source to Docker Hub, register a secret in
Kubernetes for authentication with Docker Hub.

There are [detailed instructions](https://github.com/knative/docs/blob/master/build/auth.md#basic-authentication-docker)
available, but these are the key steps.
available, but these are the key steps:

Create a new Secret manifest, which we can use to store your Docker Hub
credentials. Save this file as `docker-secret.yaml`.
1. Create a new `Secret` manifest, which is used to store your Docker Hub
credentials. Save this file as `docker-secret.yaml`:

```yaml
apiVersion: v1
Expand All @@ -59,8 +57,8 @@ data:
password: BASE64_ENCODED_PASSWORD
```

On Mac or Linux computers, you can use the following command line to generate
the base64 encoded values required for the manifest:
1. On Mac or Linux computers, use the following command to generate the base64 encoded
values required for the manifest:

```shell
$ echo -n "username" | base64
Expand All @@ -70,59 +68,59 @@ $ echo -n "password" | base64
cGFzc3dvcmQ=
```

After you have created the manifest file, apply it to your cluster with kubectl:
1. After you have created the manifest file, apply it to your cluster with `kubectl`:

```shell
$ kubectl apply -f docker-secret.yaml
secret "basic-user-pass" created
```
```shell
$ kubectl apply -f docker-secret.yaml
secret "basic-user-pass" created
```

## Deploying the sample

Now that you've configured your cluster accordingly, we're ready to deploy the
Now that you've configured your cluster accordingly, you are ready to deploy the
sample service into your cluster.

This sample uses `github.com/mchmarny/simple-app` as a basic Go application, but
you could replace this GitHub repo with your own. The only requirements are that
the repo contain a `Dockerfile` with the instructions for how to build a
the repo must contain a `Dockerfile` with the instructions for how to build a
container for the application.

Create a service manifest which defines the service to deploy, including where
the source code is and which build-template to use. Create a file named
`service.yaml` and copy the following definition. Make sure to replace
`{DOCKER_USERNAME}` with your own Docker Hub username.

```yaml
apiVersion: serving.knative.dev/v1alpha1
kind: Service
metadata:
name: app-from-source
namespace: default
spec:
runLatest:
configuration:
build:
source:
git:
url: https://github.com/mchmarny/simple-app.git
revision: master
template:
name: kaniko
arguments:
- name: IMAGE
value: &image docker.io/{DOCKER_USERNAME}/app-from-source:latest
revisionTemplate:
spec:
container:
image: *image
imagePullPolicy: Always
env:
- name: SIMPLE_MSG
value: "Hello sample app!"
```

Now you can apply this manifest using kubectl, and watch the results:

1. You need to create a service manifest which defines the service to deploy, including where
Copy link
Contributor

Choose a reason for hiding this comment

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

GitHub isn't rendering the numbers correctly. Each point is 1, so there's probably a whitespace issue here somewhere.

the source code is and which build-template to use. Create a file named
`service.yaml` and copy the following definition. Make sure to replace
`{DOCKER_USERNAME}` with your own Docker Hub username:

```yaml
apiVersion: serving.knative.dev/v1alpha1
kind: Service
metadata:
name: app-from-source
namespace: default
spec:
runLatest:
configuration:
build:
source:
git:
url: https://github.com/mchmarny/simple-app.git
revision: master
template:
name: kaniko
arguments:
- name: IMAGE
value: &image docker.io/{DOCKER_USERNAME}/app-from-source:latest
revisionTemplate:
spec:
container:
image: *image
Copy link
Member

Choose a reason for hiding this comment

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

I think that we should have a comment explaining this or just duplicate the image name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mattmoor do you mean changing this to:
image: IMAGE

Copy link
Contributor

Choose a reason for hiding this comment

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

We should change this to:

- name: IMAGE
  value: docker.io/..

spec:
  container:
    image: docker.io/...

Copy link
Contributor

Choose a reason for hiding this comment

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

Basically remove the &image and *image syntax, which is a bit of YAML magic

imagePullPolicy: Always
env:
- name: SIMPLE_MSG
value: "Hello sample app!"
```

1. Apply this manifest using `kubectl`, and watch the results:
```shell
# Apply the manifest
$ kubectl apply -f service.yaml
Expand All @@ -143,39 +141,39 @@ app-from-source-00001-deployment-6d6ff665f9-xfhm5 2/3 Running 0
app-from-source-00001-deployment-6d6ff665f9-xfhm5 3/3 Running 0 11s
```

Once you see the deployment pod switch to the running state, hit Ctrl+C to
escape the watch. The build and deployment have finished!

To check on the state of the service, get the service object and examine the
status block:

```shell
$ kubectl get service.serving.knative.dev app-from-source -o yaml

[...]
status:
conditions:
- lastTransitionTime: 2018-07-11T20:50:18Z
status: "True"
type: ConfigurationsReady
- lastTransitionTime: 2018-07-11T20:50:56Z
status: "True"
type: RoutesReady
- lastTransitionTime: 2018-07-11T20:50:56Z
status: "True"
type: Ready
domain: app-from-source.default.dibble.cloud
latestCreatedRevisionName: app-from-source-00007
latestReadyRevisionName: app-from-source-00007
observedGeneration: 10
traffic:
- configurationName: app-from-source
percent: 100
revisionName: app-from-source-00007
```


1. After the build has completed and the container is pushed to docker hub, you
1. Once you see the deployment pod switch to the running state, press Ctrl+C to
Copy link
Contributor

Choose a reason for hiding this comment

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

The numbering restarts here too, for some reason.

escape the watch. Your container is now built and deployed!

1. To check on the state of the service, get the service object and examine the
status block:

```shell
$ kubectl get service.serving.knative.dev app-from-source -o yaml

[...]
status:
conditions:
- lastTransitionTime: 2018-07-11T20:50:18Z
status: "True"
type: ConfigurationsReady
- lastTransitionTime: 2018-07-11T20:50:56Z
status: "True"
type: RoutesReady
- lastTransitionTime: 2018-07-11T20:50:56Z
status: "True"
type: Ready
domain: app-from-source.default.dibble.cloud
latestCreatedRevisionName: app-from-source-00007
latestReadyRevisionName: app-from-source-00007
observedGeneration: 10
traffic:
- configurationName: app-from-source
percent: 100
revisionName: app-from-source-00007
```


1. After the build has completed and the container is pushed to Docker Hub, you
can deploy the app into your cluster. Ensure that the container image value
in `service.yaml` matches the container you built in
the previous step. Apply the configuration using `kubectl`:
Expand All @@ -191,10 +189,8 @@ status:
* Network programming to create a route, ingress, service, and load balance for your app.
* Automatically scale your pods up and down (including to zero active pods).

1. To find the IP address for your service, use
`kubectl get svc knative-ingressgateway -n istio-system` to get the ingress IP for your
cluster. If your cluster is new, it may take sometime for the service to get asssigned
an external IP address.
1. To get the ingress IP for your cluster, use the following command. If your cluster is new,
it can take some time for the service to get an external IP address:

```shell
$ kubectl get svc knative-ingressgateway -n istio-system
Expand All @@ -204,7 +200,7 @@ status:

```

1. To find the URL for your service, use
1. To find the URL for your service, type:

```shell
$ kubectl get services.serving.knative.dev app-from-source -o=custom-columns=NAME:.metadata.name,DOMAIN:.status.domain
Expand All @@ -213,7 +209,7 @@ status:
```

1. Now you can make a request to your app to see the result. Replace
`{IP_ADDRESS}` with the address you see returned in the previous step.
`{IP_ADDRESS}` with the address that you got in the previous step:

```shell
curl -H "Host: app-from-source.default.example.com" http://{IP_ADDRESS}
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs the license footer at the bottom of this file.

Expand Down