我在 MacOS 上并使用kind v0.10.0
. 我已按照https://kind.sigs.k8s.io/docs/user/ingress/kind
提供的说明设置nginx
入口控制器(和私有 docker 注册表)。不幸的是,我无法连接到127.0.0.1:80
. 我什至尝试将我的服务、部署和入口移动到与 nginx 入口控制器相同的命名空间中,即 ie namespace=ingress-nginx
,但即使这样也没有解决任何问题。
这是我正在尝试做的事情:根据 gRPC 方法名称将传入的 gRPC 消息路由到两个单独的后端服务。
这是我正在观察的:
如果我在浏览器中打开http://127.0.0.1,我会看到502页面由
nginx
.我什至已经确认监听端口 80 的进程是
com.docker.backend
.但是,当我尝试使用 gRPC 客户端连接到此端口时,它只是挂起/超时:
% ~/go/bin/grpcurl -plaintext localhost:80 list Failed to dial target host "localhost:80": context deadline exceeded
谁能帮我调试一下?
豆荚
% kubectl get pods -n ingress-nginx
NAME READY STATUS RESTARTS AGE
ingress-nginx-admission-create-b8tkt 0/1 Completed 0 13h
ingress-nginx-admission-patch-xddd7 0/1 Completed 2 13h
ingress-nginx-controller-9ddc777c5-bwnkx 1/1 Running 0 13h
route-guide-a-6fc997cbd-7zgbk 1/1 Running 0 10m
route-guide-a-6fc997cbd-hgpjv 1/1 Running 0 10m
route-guide-b-7b954b77bb-2p8vm 1/1 Running 0 10m
route-guide-b-7b954b77bb-nmdnt 1/1 Running 0 10m
部署
% kubectl get deployment -n ingress-nginx
NAME READY UP-TO-DATE AVAILABLE AGE
ingress-nginx-controller 1/1 1 1 13h
route-guide-a 2/2 2 2 10m
route-guide-b 2/2 2 2 10m
服务
% kubectl get svc -n ingress-nginx
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ingress-nginx-controller NodePort 10.96.230.48 <none> 80:32236/TCP,443:32573/TCP 13h
ingress-nginx-controller-admission ClusterIP 10.96.79.228 <none> 443/TCP 13h
route-guide-a ClusterIP 10.96.249.171 <none> 10000/TCP 11m
route-guide-b ClusterIP 10.96.143.194 <none> 10000/TCP 11m
入口
% kubectl get ingress -n ingress-nginx
NAME CLASS HOSTS ADDRESS PORTS AGE
route-guide-ingress <none> * localhost 80 12m
配置文件
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: route-guide-a
namespace: ingress-nginx
labels:
app: route-guide-a
spec:
replicas: 2
selector:
matchLabels:
app: route-guide-a
template:
metadata:
labels:
app: route-guide-a
spec:
containers:
- name: route-guide-a
image: localhost:5000/route_guide:v4
imagePullPolicy: IfNotPresent
command: ["/usr/local/go/bin/go", "run", "server/server.go"]
ports:
- containerPort: 10000
name: grpc-port
env:
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: route-guide-b
namespace: ingress-nginx
labels:
app: route-guide-b
spec:
replicas: 2
selector:
matchLabels:
app: route-guide-b
template:
metadata:
labels:
app: route-guide-b
spec:
containers:
- name: route-guide-b
image: localhost:5000/route_guide:v4
imagePullPolicy: IfNotPresent
command: ["/usr/local/go/bin/go", "run", "server/server.go"]
ports:
- containerPort: 10000
name: grpc-port
env:
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
---
apiVersion: v1
kind: Service
metadata:
name: route-guide-a
namespace: ingress-nginx
labels:
app: route-guide-a
spec:
# type: NodePort
selector:
app: route-guide-a
ports:
- port: 10000
# nodePort: 31397
targetPort: 10000
name: grpc-port
protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
name: route-guide-b
namespace: ingress-nginx
labels:
app: route-guide-b
spec:
# type: NodePort
selector:
app: route-guide-b
ports:
- port: 10000
# nodePort: 31398
targetPort: 10000
name: grpc-port
protocol: TCP
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: "nginx"
# nginx.ingress.kubernetes.io/ssl-redirect: "true"
nginx.ingress.kubernetes.io/backend-protocol: "GRPC"
name: route-guide-ingress
namespace: ingress-nginx
spec:
rules:
- http:
paths:
- path: /routeguide.RouteGuide/GetFeature
backend:
serviceName: route-guide-a
servicePort: grpc-port
- path: /routeguide.RouteGuide/ListFeatures
backend:
serviceName: route-guide-a
servicePort: grpc-port
- path: /routeguide.RouteGuide/RecordRoute
backend:
serviceName: route-guide-b
servicePort: grpc-port
- path: /routeguide.RouteGuide/RouteChat
backend:
serviceName: route-guide-b
servicePort: grpc-port
# catch-all route
- backend:
serviceName: route-guide-b
servicePort: grpc-port
正在运行的集群中的入口配置
以下命令的输出:kubectl get ingress -n ingress-nginx route-guide-ingress -o yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"networking.k8s.io/v1beta1","kind":"Ingress","metadata":{"annotations":{"kubernetes.io/ingress.class":"nginx","nginx.ingress.kubernetes.io/backend-protocol":"GRPC"},"name":"route-guide-ingress","namespace":"ingress-nginx"},"spec":{"rules":[{"http":{"paths":[{"backend":{"serviceName":"route-guide-a","servicePort":"grpc-port"},"path":"/routeguide.RouteGuide/GetFeature"},{"backend":{"serviceName":"route-guide-a","servicePort":"grpc-port"},"path":"/routeguide.RouteGuide/ListFeatures"},{"backend":{"serviceName":"route-guide-b","servicePort":"grpc-port"},"path":"/routeguide.RouteGuide/RecordRoute"},{"backend":{"serviceName":"route-guide-b","servicePort":"grpc-port"},"path":"/routeguide.RouteGuide/RouteChat"},{"backend":{"serviceName":"route-guide-a","servicePort":"grpc-port"}}]}}]}}
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/backend-protocol: GRPC
creationTimestamp: "2021-05-02T02:57:24Z"
generation: 2
managedFields:
- apiVersion: networking.k8s.io/v1beta1
fieldsType: FieldsV1
fieldsV1:
f:metadata:
f:annotations:
.: {}
f:kubectl.kubernetes.io/last-applied-configuration: {}
f:kubernetes.io/ingress.class: {}
f:nginx.ingress.kubernetes.io/backend-protocol: {}
f:spec:
f:rules: {}
manager: kubectl-client-side-apply
operation: Update
time: "2021-05-02T02:57:24Z"
- apiVersion: networking.k8s.io/v1beta1
fieldsType: FieldsV1
fieldsV1:
f:status:
f:loadBalancer:
f:ingress: {}
manager: nginx-ingress-controller
operation: Update
time: "2021-05-02T02:57:44Z"
name: route-guide-ingress
namespace: ingress-nginx
resourceVersion: "12115"
uid: be3862b4-13a7-4b96-b5f8-399e28bb373c
spec:
rules:
- http:
paths:
- backend:
service:
name: route-guide-a
port:
name: grpc-port
path: /routeguide.RouteGuide/GetFeature
pathType: ImplementationSpecific
- backend:
service:
name: route-guide-a
port:
name: grpc-port
path: /routeguide.RouteGuide/ListFeatures
pathType: ImplementationSpecific
- backend:
service:
name: route-guide-b
port:
name: grpc-port
path: /routeguide.RouteGuide/RecordRoute
pathType: ImplementationSpecific
- backend:
service:
name: route-guide-b
port:
name: grpc-port
path: /routeguide.RouteGuide/RouteChat
pathType: ImplementationSpecific
- backend:
service:
name: route-guide-a
port:
name: grpc-port
pathType: ImplementationSpecific
status:
loadBalancer:
ingress:
- hostname: localhost