* chore: use buildx to build grpc-ping-go Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support grpc-ping-go multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support helloworld-clojure multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support helloworld-dart multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support helloworld-deno multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support helloworld-elixir multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support helloworld-haskell multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support helloworld-java-micronaut multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support helloworld-java-quarkus multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support helloworld-r multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support helloworld-rserver multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support helloworld-rust multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support helloworld-swift multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support helloworld-vertx multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support iris-classifier multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support helloworld-go multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support helloworld-python multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support node-heartbeat-source multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support cloudevents-dotnet multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support cloudevents-go multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support cloudevents-nodejs multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support cloudevents-rust multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support gitwebhook-go multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support helloworld-csharp multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support helloworld-go multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support helloworld-java-spark multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support helloworld-java-spring multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support helloworld-kotlin multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support helloworld-nodejs multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support helloworld-php multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support helloworld-python multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support helloworld-shell multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support knative-routing-go multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support kong-routing-go multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support multi-container multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support secrets-go multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support knative-docs multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support helloworld-r Dockerfile multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support helloworld-go Dockerfile multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support cloudevents-go Dockerfile multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support gitwebhook-go Dockerfile multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support knative-routing-go Dockerfile multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support kong-routing-go Dockerfile multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support servingcontainer Dockerfile multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support sidecarcontainer Dockerfile multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support secrets-go Dockerfile multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> * chore: support multi-container Dockerfile multiple architecture Signed-off-by: kahirokunn <okinakahiro@gmail.com> --------- Signed-off-by: kahirokunn <okinakahiro@gmail.com> |
||
---|---|---|
.. | ||
client | ||
proto | ||
Dockerfile | ||
README.md | ||
grpc-ping.go | ||
service.yaml |
README.md
gRPC Server - Go
A gRPC 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. See Install Knative Serving.
-
Install docker.
-
A Docker Hub account to which you can upload the sample's container image.
Build and Deploy the sample code
- Download a copy of the code:
git clone https://github.com/knative/docs.git knative-docs
cd knative-docs/code-samples/serving/grpc-ping-go
- Use Docker to build a container image for this service and push to Docker Hub.
Replace {username}
with your Docker Hub username then run the commands:
# Build and push the container on your local machine.
docker buildx build --platform linux/arm64,linux/amd64 -t "{username}/grpc-ping-go" --push .
-
Update the
service.yaml
file in the project to reference the published image from step 1.Replace
{username}
inservice.yaml
with your Docker Hub user name:
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: grpc-ping
namespace: default
spec:
template:
spec:
containers:
- image: docker.io/{username}/grpc-ping-go
ports:
- name: h2c
containerPort: 8080
- Use
kubectl
to deploy the service.
kubectl apply --filename service.yaml
Response:
service "grpc-ping" created
Exploring
Once deployed, you can inspect the created resources with kubectl
commands:
# 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
Testing the service
Testing the gRPC service requires using a gRPC client built from the same protobuf definition used by the 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:
docker run --rm {username}/grpc-ping-go \
/client \
-server_addr="grpc-ping.default.1.2.3.4.sslip.io:80" \
-insecure
The arguments after the container tag {username}/grpc-ping-go
are used
instead of the entrypoint command defined in the Dockerfile CMD
statement.