Kubernetes:无法在部署/服务之间进行通信

时间:2020-07-29 17:09:06

标签: amazon-web-services docker kubernetes microservices google-kubernetes-engine

这里需要一些认真的帮助,在此先感谢。

我需要部署一个编写的微服务应用程序。我只需要调试为什么前端 webapp服务无法连接到后端 auth服务

如果解决了这个问题,我会将这个解决方案复制到所有其他微服务中。

流程:

  1. 用户在 webapp服务登录页面上输入用户名和密码,并请求 FIRST 转到webapp的/ login路由处理程序。
  2. Webapp服务的'/ login'路由处理程序接收JSON数据,然后 THEN 将其发送到 auth服务,后者也侦听'/ login'路由。 / li>

简而言之,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"}



如果需要在此处添加更多信息,请告诉我。

0 个答案:

没有答案