-
Notifications
You must be signed in to change notification settings - Fork 1.3k
samples/grpc-ping-go: align with knative sample and README practices #1753
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a1a834f
samples/grpc-ping-go: align with knative sample and README practices
grayside 74cb84b
samples/grpc-ping-go: use 0.0.0.0 instead of localhost inside container
grayside 8a096a0
samples/grpc-ping-go: clarity & context improvements
grayside 4a8a148
serving/samples: remove unneeded -it flag from grpc-ping testing
grayside File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,59 +1,127 @@ | ||
| --- | ||
| title: "gRPC server - Go" | ||
| title: "gRPC Server - Go" | ||
| #linkTitle: "" | ||
| weight: 1 | ||
| type: "docs" | ||
| --- | ||
|
|
||
| A simple gRPC server written in Go that you can use for testing. | ||
| A [gRPC](https://grpc.io) server written in Go. | ||
|
|
||
| This sample can be used to try out gRPC, HTTP/2, and custom port configuration | ||
| in a knative service. | ||
|
|
||
| The container image is built with two binaries: the server and the client. | ||
| This is done for ease of testing and is not a recommended practice | ||
| for production containers. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - [Install the latest version of Knative Serving](../../../install/README.md). | ||
|
|
||
| - Install [docker](https://www.docker.com/). | ||
|
|
||
| - Download a copy of the code: | ||
| - A [Docker Hub account](https://hub.docker.com) to which you can upload the sample's container image. | ||
|
|
||
| ## Build and Deploy the sample code | ||
|
|
||
| 1. Download a copy of the code: | ||
|
|
||
| ```shell | ||
| git clone -b "{{< branch >}}" https://github.com/knative/docs knative-docs | ||
| cd knative-docs/docs/serving/samples/grpc-ping-go | ||
| ``` | ||
|
|
||
| ## Build and run the gRPC server | ||
| 2. Use Docker to build a container image for this service and push to Docker Hub. | ||
|
|
||
| First, build and publish the gRPC server to DockerHub (replacing `{username}`): | ||
| Replace `{username}` with your Docker Hub username then run the commands: | ||
|
|
||
| ```shell | ||
| # Build and publish the container, run from the root directory. | ||
| docker build \ | ||
| --tag "docker.io/{username}/grpc-ping-go" \ | ||
| --file=docs/serving/samples/grpc-ping-go/Dockerfile . | ||
| docker push "docker.io/{username}/grpc-ping-go" | ||
| ``` | ||
| ```shell | ||
| # Build the container on your local machine. | ||
| docker build --tag "{username}/grpc-ping-go" . | ||
|
|
||
| # Push the container to docker registry. | ||
| docker push "{username}/grpc-ping-go" | ||
| ``` | ||
|
|
||
| 3. Update the `service.yaml` file in the project to reference the published image from step 1. | ||
|
|
||
| Replace `{username}` in `service.yaml` with your Docker Hub user name: | ||
|
|
||
|
|
||
| ```yaml | ||
| apiVersion: serving.knative.dev/v1alpha1 | ||
| kind: Service | ||
| metadata: | ||
| name: grpc-ping | ||
| namespace: default | ||
| spec: | ||
| template: | ||
| spec: | ||
| containers: | ||
| - image: docker.io/{username}/grpc-ping-go | ||
| ports: | ||
| - name: h2c | ||
| containerPort: 8080 | ||
| ``` | ||
|
|
||
| 4. Use `kubectl` to deploy the service. | ||
|
|
||
| ```shell | ||
| kubectl apply --filename service.yaml | ||
| ``` | ||
|
|
||
| Next, replace `{username}` in `sample.yaml` with your DockerHub username, and | ||
| apply the yaml. | ||
| Response: | ||
|
|
||
| ```shell | ||
| service "grpc-ping" created | ||
| ``` | ||
|
|
||
| ## Exploring | ||
|
|
||
| Once deployed, you can inspect the created resources with `kubectl` commands: | ||
|
|
||
| ```shell | ||
| kubectl apply --filename docs/serving/samples/grpc-ping-go/sample.yaml | ||
| # This will show the Knative service that we created: | ||
| kubectl get ksvc --output yaml | ||
|
|
||
| # This will show the Route, created by the service: | ||
| kubectl get route --output yaml | ||
|
|
||
| # This will show the Configuration, created by the service: | ||
| kubectl get configurations --output yaml | ||
|
|
||
| # This will show the Revision, created by the Configuration: | ||
| kubectl get revisions --output yaml | ||
| ``` | ||
|
|
||
| ## Use the client to stream messages to the gRPC server | ||
| ## Testing the service | ||
|
|
||
| Testing the gRPC service requires using a gRPC client built from the same | ||
| protobuf definition used by the server. | ||
|
|
||
| 1. Fetch the created ingress hostname and IP. | ||
|
|
||
| ```shell | ||
| # Put the ingress IP into an environment variable. | ||
| export SERVICE_IP=`kubectl get svc istio-ingressgateway --namespace istio-system --output jsonpath="{.status.loadBalancer.ingress[*].ip}"` | ||
| export SERVICE_IP=$(kubectl get svc istio-ingressgateway --namespace istio-system --output jsonpath="{.status.loadBalancer.ingress[*].ip}") | ||
| ``` | ||
|
|
||
| 1. Use the client to send message streams to the gRPC server (replacing | ||
| `{username}`) | ||
| 1. Use the gRPC client to send message streams to the gRPC server. | ||
|
|
||
| The Dockerfile builds the client binary. To run the client you will use the | ||
| same container image deployed for the server with an override to the | ||
| entrypoint command to use the client binary instead of the server binary. | ||
|
|
||
| Replace `{username}` with your Docker Hub user name and run the command: | ||
|
|
||
| ```shell | ||
| docker run -ti --entrypoint=/client docker.io/{username}/grpc-ping-go \ | ||
| docker run --rm {username}/grpc-ping-go \ | ||
| /client \ | ||
| -server_addr="${SERVICE_IP}:80" \ | ||
| -server_host_override="grpc-ping.default.example.com" \ | ||
| -insecure | ||
| ``` | ||
|
|
||
| The arguments after the container tag `{username}/grpc-ping-go` are used | ||
| instead of the entrypoint command defined in the Dockerfile `CMD` statement. | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.