这里需要一些认真的帮助,在此先感谢。
我需要部署一个编写的微服务应用程序。我只需要调试为什么前端 webapp服务无法连接到后端 auth服务。
如果解决了这个问题,我会将这个解决方案复制到所有其他微服务中。
流程:
简而言之,webapp-service将JSON发送到auth-service的/ login路由。
这是URL webapp服务正在将数据发送到'http:// auth-srv / login'。 http:// auth-srv 是用于auth-microservice部署的kubernetes服务(ClusterIP)。
现在,我已经解释了,我将显示Kubernetes文件。
Webapp微服务的Deployment + Service(ClusterIP):
apiVersion: apps/v1
kind: Deployment
metadata:
name: webapp-depl
spec:
replicas: 2
selector:
matchLabels:
app: webapp
template:
metadata:
labels:
app: webapp
spec:
containers:
- name: webapp
image: <docker_id>/webapp
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: webapp-srv
spec:
type: ClusterIP
selector:
app: webapp
ports:
- name: webapp
protocol: TCP
port: 8080
targetPort: 8080
验证微服务的Deployment + Service(ClusterIP):
apiVersion: apps/v1
kind: Deployment
metadata:
name: auth-depl
spec:
replicas: 2
selector:
matchLabels:
app: auth
template:
metadata:
labels:
app: auth
spec:
containers:
- name: auth
image: <docker_id>/auth
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: auth-srv
spec:
type: ClusterIP
selector:
app: auth
ports:
- name: auth
protocol: TCP
port: 8080
targetPort: 8080
Ingress Nginx配置:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-service
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/use-regex: 'true'
spec:
rules:
- host: <my_domain_name>
http:
paths:
- path: /auth/?(.*)
backend:
serviceName: auth-srv
servicePort: 8080
- path: /emotion/?(.*)
backend:
serviceName: emotion-srv
servicePort: 8080
- path: /storage/?(.*)
backend:
serviceName: storage-srv
servicePort: 8080
- path: /voice/?(.*)
backend:
serviceName: voice-srv
servicePort: 8080
- path: /backend/?(.*)
backend:
serviceName: backend-srv
servicePort: 8080
- path: /reporting/?(.*)
backend:
serviceName: reporting-srv
servicePort: 8080
- path: /?(.*)
backend:
serviceName: webapp-srv
servicePort: 8080
Webapp和Auth服务信息:
$ kubectl describe svc webapp-srv
Name: webapp-srv
Namespace: default
Labels: <none>
Annotations: <none>
Selector: app=webapp
Type: ClusterIP
IP: 10.100.20.170
Port: webapp 8080/TCP
TargetPort: 8080/TCP
Endpoints: 192.169.25.58:8080,192.169.49.234:8080
Session Affinity: None
Events: <none>
$ kubectl describe svc auth-srv
Name: auth-srv
Namespace: default
Labels: <none>
Annotations: kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"auth-srv","namespace":"default"},"spec":{"ports":[{"name":"auth",...
Selector: app=auth
Type: ClusterIP
IP: 10.100.208.118
Port: auth 8080/TCP
TargetPort: 8080/TCP
Endpoints: 192.169.13.60:8080,192.169.44.136:8080
Session Affinity: None
Events: <none>
Webapp微服务POD错误日志:
springframework.web.client.ResourceAccessException:
I/O error on POST request for "http://auth-srv/login":
Operation timed out (Connection timed out); nested exception is java.net.ConnectException: Operation timed out (Connection timed out)
我尝试了从另一个容器到我为测试而创建的Auth-微服务的群集IP的一些curl命令:
$ curl -o - --header "Content-Type: application/json" \
--request POST \
--data '{"email":"myemail@domain.com","password":"password"}' 192.169.13.60:8080/login
######### response #########
{"timestamp":1596053074178,"status":404,"error":"Not Found","message":"No message available","path":"/l"}
$ curl -o - 192.168.13.60:8080/login
######### response #########
{"timestamp":1596053136734,"status":405,"error":"Method Not Allowed","exception":"org.springframework.web.HttpRequestMethodNotSupportedException","message":"Request method 'GET' not supported","path":"/login"}
如果需要在此处添加更多信息,请告诉我。