ambassador 学习四 grpc 处理
实际上都是envoy 的功劳
基本环境安装参考相关文档即可
参考demo
- proto code
syntax = "proto3";
option java_multiple_files = true;
option java_package = "io.grpc.examples.helloworld";
option java_outer_classname = "HelloWorldProto";
package helloworld;
// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}
}
// The request message containing the user's name.
message HelloRequest {
string name = 1;
}
// The response message containing the greetings
message HelloReply {
string message = 1;
}curl -v -H "x-ambassador-test-allow: probably" http://localhost:32190//qotm/quote/1
- 部署&& 配置(所用官方yaml文件)
---
apiVersion: v1
kind: Service
metadata:
labels:
service: grpc-greet
name: grpc-greet
annotations:
getambassador.io/config: |
---
apiVersion: ambassador/v0
kind: Mapping
name: grpc_mapping
grpc: true
prefix: /helloworld.Greeter/
rewrite: /helloworld.Greeter/
service: grpc-greet
spec:
type: ClusterIP
ports:
- port: 80
name: grpc-greet
targetPort: grpc-api
selector:
service: grpc-greet
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: grpc-greet
spec:
replicas: 1
template:
metadata:
labels:
service: grpc-greet
spec:
containers:
- name: grpc-greet
image: enm10k/grpc-hello-world
ports:
- name: grpc-api
containerPort: 9999
env:
- name: PORT
value: "9999"
command:
- greeter_server
restartPolicy: Always
kubectl apply -f demo-grpc.yaml
部署状态
测试
- 测试脚本
docker run -e ADDRESS=10.6.245.140:32190 enm10k/grpc-hello-world greeter_client
测试结果
参考资料
https://www.getambassador.io/user-guide/grpc
https://github.com/rongfengliang/ambassador-learning