简体   繁体   English

无法从 kubernetes 集群上的 angular pod 向服务发出 GET 请求

[英]Cannot make GET request to service from angular pod on kubernetes cluster

I have an Angular app running on Nginx deployed along with Spring Boot rest service.我有一个在 Nginx 上运行的 Angular 应用程序与 Spring 启动 Z65E8800B5C6800AAD896F888B 服务一起部署。 When I launch docker containers locally everything works fine so my only guess is that something wrong with Kubernetes configuration.当我在本地启动 docker 容器时,一切正常,所以我唯一的猜测是 Kubernetes 配置有问题。

I receive this error in Chrome console with IP address provided Failed to load resource: net::ERR_CONNECTION_TIMED_OUT However, with DNS name I get: Failed to load resource: net::ERR_NAME_NOT_RESOLVED我在 Chrome 控制台中收到此错误,提供 IP 地址Failed to load resource: net::ERR_CONNECTION_TIMED_OUT但是,使用 DNS 名称我得到: Failed to load resource: net::ERR_NAME_NOT_RESOLVED

Strangely, I am able to curl my service from radial/busyboxplus:curl pod but I cannot ping my service from my front pod (don't have a curl in build).奇怪的是,我可以 curl 我的服务从radial/busyboxplus:curl吊舱,但我无法从我的前吊舱 ping 我的服务(在 build 中没有 ZF6E57C9DE709E45354ZZ)5315。

I am accessing front through ingress:我正在通过入口访问前端:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: main-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
    - http:
        paths:
          - path: /
            backend:
              serviceName: front
              servicePort: 80

My frontend:我的前端:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: product-adviser-front-deployment
  labels:
    app: angular-front
    version: v1
spec:
  replicas: 1
  selector:
    matchLabels:
      name: product-adviser-front-deployment
  template:
    metadata:
      labels:
        name: product-adviser-front-deployment
    spec:
      containers:
        - name: product-adviser-front-app
          image: aurrix/seb:product-adviser-front
          imagePullPolicy: Always
          ports:
            - containerPort: 80
          env:
            - name: API_URL
              value: http://back.default.svc.cluster.local/
          readinessProbe:
            initialDelaySeconds: 30
            httpGet:
              path: /healthz
              port: 80
          livenessProbe:
            initialDelaySeconds: 30
            httpGet:
              path: /healthz
              port: 80
      restartPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
  name: front
spec:
  selector:
    name: product-adviser-front-deployment
  ports:
    - port: 80
  type: NodePort

My backend:我的后端:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: product-adviser-back-deployment
  labels:
    app: backend-service
    version: v1
spec:
  replicas: 1
  selector:
    matchLabels:
      name: product-adviser-back-deployment
  template:
    metadata:
      labels:
        name: product-adviser-back-deployment
    spec:
      containers:
        - name: product-adviser-back-deployment
          image: aurrix/seb:product-adviser
          imagePullPolicy: Always
          ports:
            - containerPort: 8080
          readinessProbe:
            initialDelaySeconds: 30
            httpGet:
              path: /actuator/health
              port: 8080
          livenessProbe:
            initialDelaySeconds: 30
            httpGet:
              path: /actuator/health
              port: 8080
      restartPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
  name: back
spec:
  selector:
    name: product-adviser-back-deployment
  ports:
    - port: 80
      targetPort: 8080

You have set value: http://back.default.svc.cluster.local/ as env, are you calling this endpoint for backend service from your front-end app?您已设置值: http://back.default.svc.cluster.local/作为环境,您是否从前端应用程序调用此端点以获取后端服务? If so, this will not work as frontend application runs on browser and it is the browser that will make the API call.如果是这样,这将不起作用,因为前端应用程序在浏览器上运行,并且浏览器将进行 API 调用。 In this case you will have to add another rule in the ingress and route the requests to backend pod.在这种情况下,您必须在入口中添加另一个规则并将请求路由到后端 pod。

I also noticed the frontend service is set to nodePort and from ingress you are calling the service directly.我还注意到前端服务设置为 nodePort 并且从入口直接调用该服务。 You may want to set the service to cluster-IP(default) like the backend service.您可能希望像后端服务一样将服务设置为集群 IP(默认)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法从 kube.netes 集群上的 angular pod 向 Ocelot Gateway 服务发出 HTTP 请求 - Cannot make HTTP requests to Ocelot Gateway service from angular pod on kubernetes cluster Angular、NGINX 无法连接到 Kubernetes 集群上的后端 - Angular, NGINX cannot connect to backend on Kubernetes cluster 如何在带有可观察对象的Angular 2 http服务中使http获取请求 - how to make http get request in angular 2 http service with observables 从 Angular 执行来自 service worker 的 get 请求 - Perform a get request from a service worker based from Angular 通过对 Nutritionix API 的发布请求,无法从服务方法 getNutrition() 获取 JSON 数据。 新使用 api 和 angular - Cannot get the JSON data from service method getNutrition() through post request to Nutritionix API. New to using api and angular Angular make http get request 然后用get request中的数据make put request - Angular make http get request then with data from get request make put request 如何摆脱Angular 6服务中的冗余请求? - How to get rid from redundant request in Angular 6 service? 在“ getter”方法Angular 7服务中从HttpGet请求获取结果 - Get result from HttpGet Request in “getter” method Angular 7 service Angular2无法从Service获取模拟数据 - Angular2 cannot get mock data from Service angular2-无法从Web服务获取数据 - angular2 - cannot get data from web service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM