- 在 gRPC 服务器代码中将监听端口更改为30000:
 
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
add_MyServiceServicer_to_server(MyServiceServicer(), server)
server.add_insecure_port('[::]:30000')
server.start()
- 如果您的 gRPC 应用程序托管在 Kubernetes 上,可以在 Kubernetes 部署文件中定义端口转发规则,以将集群中的请求重定向到 gRPC 容器的端口30000:
 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: grpc-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: grpc-app
  template:
    metadata:
      labels:
        app: grpc-app
    spec:
      containers:
        - name: grpc-server
          image: your/grpc-image
          ports:
            - name: grpc
              containerPort: 30000
      - name: proxy
        image: your/proxy-image
        ports:
          - name: https
            containerPort: 443
        volumeMounts:
          - mountPath: /etc/nginx/nginx.conf
            name: nginx-config
        livenessProbe:
          httpGet:
            path: /healthz
            port: https
          initialDelaySeconds: 30
          timeoutSeconds: 3
      volumes:
        - name: nginx-config
          configMap:
            name: nginx-config