Skip to content

Instantly share code, notes, and snippets.

@gbrayut
Created July 30, 2024 18:09
Show Gist options
  • Save gbrayut/b0b3d75b6b5b84782884ad119f64881d to your computer and use it in GitHub Desktop.
Save gbrayut/b0b3d75b6b5b84782884ad119f64881d to your computer and use it in GitHub Desktop.
GKE grpc gateway testing
# Modified from https://gist.github.com/gauravkghildiyal/a3ed6aaf7010835b5e3d253c2472aef2
# Changes: Use TCP health check, one service instead of two, and set grpc as default instead of only explicit routes.
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: grpc-app
name: grpc
spec:
replicas: 1
selector:
matchLabels:
app: grpc-app
template:
metadata:
labels:
app: grpc-app
spec:
containers:
- name: echo
image: kalmhq/echoserver:latest
ports:
- name: http-port
containerPort: 8001
- name: http2-tls-port
containerPort: 8003
- name: grpc-tls-port
containerPort: 8005
---
kind: Gateway
apiVersion: gateway.networking.k8s.io/v1beta1
metadata:
name: grpc-gateway
spec:
gatewayClassName: gke-l7-global-external-managed
listeners:
- name: https
protocol: HTTPS
port: 443
tls:
mode: Terminate
certificateRefs:
- name: example-dot-com-certificate
---
kind: HTTPRoute
apiVersion: gateway.networking.k8s.io/v1beta1
metadata:
name: grpc-httproute
spec:
parentRefs:
- kind: Gateway
name: grpc-gateway
rules:
# Optional test endpoint for http2 backend
- matches:
- path:
type: PathPrefix
value: /test
backendRefs:
- name: grpc-svc
port: 8080
# Use gRPC TLS service as default backend
- matches:
- path:
type: PathPrefix
value: /
backendRefs:
- name: grpc-svc
port: 80
---
apiVersion: v1
kind: Service
metadata:
name: grpc-svc
spec:
type: ClusterIP
selector:
app: grpc-app
ports:
- name: grpc-tls
port: 80
protocol: TCP
appProtocol: HTTP2
targetPort: 8005
- name: http2-tls
port: 8080
protocol: TCP
appProtocol: HTTP2
targetPort: 8003
---
apiVersion: networking.gke.io/v1
kind: HealthCheckPolicy
metadata:
name: grpc-gateway-healthcheck
spec:
default:
checkIntervalSec: 15
timeoutSec: 15
healthyThreshold: 1
unhealthyThreshold: 2
logConfig:
enabled: true
config:
# Recommend TCP or GRPC health check. See https://cloud.google.com/load-balancing/docs/health-check-concepts
type: TCP
tcpHealthCheck:
port: 8005
targetRef:
group: ""
kind: Service
name: grpc-svc
@gbrayut
Copy link
Author

gbrayut commented Jul 30, 2024

Test commands and screenshots:

kubectl get events -n my-namespace
kubectl describe gateway grpc-gateway -n my-namespace
Also check for errors at https://console.cloud.google.com/kubernetes/gateways
or LB/Backend health and monitoring details at https://console.cloud.google.com/net-services/loadbalancing/list/loadBalancers

# After 5-10 minutes you should be able to run tests like
curl -vsk --resolve grpc.example.com:443:<GATEWAY_IP> https://grpc.example.com/test
grpcurl -vv -insecure -authority grpc.example.com <GATEWAY_IP>:443 main.HelloWorld/Greeting

2024-07-30_11-57

2024-07-30_12-09

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment