Deploying your gRPC Service in Kubernetes
此页面介绍了如何在 Kubernetes 中部署你的 gRPC 服务。我们将继续 the Getting Started gRPC guide 中的示例。
This page explains how to deploy your gRPC service in Quarkus in Kubernetes. We’ll continue with the example from the Getting Started gRPC guide.
Configuring your project to use the Quarkus Kubernetes extension
将 Quarkus Kubernetes 扩展添加到你的构建文件中:
Add the Quarkus Kubernetes extension to your build file:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kubernetes</artifactId>
</dependency>
implementation("io.quarkus:quarkus-kubernetes")
接下来,我们希望使用 Kubernetes Ingress 资源公开我们的应用程序:
Next, we want to expose our application using the Kubernetes Ingress resource:
quarkus.kubernetes.ingress.expose=true
Quarkus Kubernetes 将使用端口名称 http
绑定 HTTP 服务器,并使用端口名称 grpc
绑定 gRPC 服务器。默认情况下,Quarkus 应用程序将只公开端口名称 http
,因此只有 HTTP 服务器可以公开访问。若要公开 gRPC 服务器,请在 application.properties 中设置 quarkus.kubernetes.ingress.target-port=grpc
属性:
The Quarkus Kubernetes will bind the HTTP server using the port name http
and the gRPC server using the port name grpc
. By default, the Quarkus application will only expose the port name http
, so only the HTTP server will be publicly accessible. To expose the gRPC server instead, set the quarkus.kubernetes.ingress.target-port=grpc
property in your application.properties:
quarkus.kubernetes.ingress.target-port=grpc
如果你将 Quarkus 配置为使用属性 |
If you configure Quarkus to use the same port for both HTTP and gRPC servers with the property |
最后,我们需要通过在终端中运行命令来生成 Kubernetes 清单:
Finally, we need to generate the Kubernetes manifests by running the command in a terminal:
Unresolved directive in grpc-kubernetes.adoc - include::{includes}/devtools/build.adoc[]
生成后,你可以查看 target/kubernetes
目录:
Once generated, you can look at the target/kubernetes
directory:
target/kubernetes
└── kubernetes.json
└── kubernetes.yml
你可以在 the Kubernetes guide 中找到有关如何在 Kubernetes 中部署应用程序的更多信息。
You can find more information about how to deploy the application in Kubernetes in the the Kubernetes guide.
Using gRPC Health probes
默认情况下,Kubernetes 资源不包含准备或活动探测。若要添加它们,请将 Smallrye Health 扩展导入你的构建文件:
By default, the Kubernetes resources do not contain readiness and liveness probes. To add them, import the Smallrye Health extension to your build file:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-health</artifactId>
</dependency>
implementation("io.quarkus:quarkus-smallrye-health")
你可以在 the SmallRye Health guide 中找到有关 Health 扩展的更多信息。 |
More information about the health extension can be found in the SmallRye Health guide. |
默认情况下,此扩展将配置探测以使用 HTTP 服务器(由一些扩展提供,如 Quarkus REST(以前称为 RESTEasy Reactive)扩展)。在内部,此探测还会使用 the generated gRPC Health services。
By default, this extension will configure the probes to use the HTTP server (which is provided by some extensions like the Quarkus REST (formerly RESTEasy Reactive) extension). Internally, this probe will also use the generated gRPC Health services.
如果你的应用程序不使用公开 HTTP 服务器的任何 Quarkus 扩展,你仍然可以通过将属性 quarkus.kubernetes.readiness-probe.grpc-action-enabled=true
添加到你的配置中来配置探测以直接使用 gRPC Health 服务:
If your application does not use any Quarkus extension that exposes an HTTP server, you can still configure the probes to directly use the gRPC Health service by adding the property quarkus.kubernetes.readiness-probe.grpc-action-enabled=true
into your configuration:
quarkus.kubernetes.readiness-probe.grpc-action-enabled=true