简体   繁体   English

在使用 nginx 入口时,我可以通过 POD IP 地址(而不是主机地址)获得 curl 的响应吗

[英]Can I get response of curl through POD IP address (instead of host address) while using nginx ingress

I am using nginx ingress controller below is the ingress rule file for 2 services:我正在使用nginx ingress controller下面是 2 个服务的入口规则文件:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
  namespace: kube-system
  annotations:
    kubernetes.io/ingress.class: nginx
    kubernetes.io/ingress.allow-http: "false"
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/use-regex: "true"
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  tls:
  - hosts:
    - rewrite.bar.com.com
    secretName: ingress-tls
  rules:
  - host: rewrite.bar.com.com
  - http:
      paths:
      - path: /my-service-1/(.*)
        pathType: Prefix
        backend:
          service:
            name: my-service-1
            port:
              number: 36995
      - path: /my-service-2/(.*)
        pathType: Prefix
        backend:
          service:
            name: my-service-2
            port:
              number: 32243

Now using below command through shell of service-2 I can curl to the service-1 api endpoint, here I need to pass host ('wire.com') which is TLS enabled as well,现在通过 service-2 的 shell 使用以下命令我可以 curl 到 service-1 api 端点,这里我需要传递主机('wire.com')

curl --resolve wire.com:443:10.22.148.179 https://wire.com:32243/GetData

Above curl using host address give me response successfully, no issue here!以上 curl 使用主机地址给我回复成功,这里没有问题!

Now I am using IP address of the POD instead of host address, but this won't give me response, it's always give error like curl: (52) Empty reply from server .现在我使用的是 POD 的 IP 地址而不是主机地址,但这不会给我响应,它总是给出像curl: (52) Empty reply from server之类的错误。 Here 10.22.148.179 is my ingress public IP address and 10.2.0.58 is my POD IP address.这里10.22.148.179是我的入口公共 IP 地址, 10.2.0.58是我的 POD IP 地址。

curl --resolve enabledservices-dev-aks.honeywell.com:443:10.22.148.179 http//10.2.0.58:32243/GetData

My goal to hit the POD/service api end point through IP address, is this possible with context of Ingress integrated?我的目标是通过 IP 地址到达 POD/服务 api 端点,这可能与 Ingress 集成的上下文有关吗?

Moving this from comments to answer.将此从评论转移到答案。


The issue was curl request and HTTP protocol used while the server is serving by HTTPS.问题是在服务器由 HTTPS 提供服务时使用了 curl 请求和 HTTP 协议。 This is the reason of (52) Empty reply from server error.这是(52) Empty reply from server error 的原因。

Request by curl should be done by specifying the protocol like: curl 的请求应通过指定如下协议来完成:

curl https://test.example.com:8888

Ingress is used as a single entry point to the cluster so all inside services can be exposed internally in the cluster using cluster-ip service type - see kubernetes service types . Ingress用作集群的单个入口点,因此可以使用cluster-ip服务类型在集群内部公开所有内部服务 - 请参阅kubernetes 服务类型

If any inside service/pod is required to be tested from inside the cluster, request should be executed from the cluster to be able to hit a cluster-ip since cluster-ip is only accessible within the cluster.如果需要从集群内部测试任何内部服务/pod,则应从集群执行请求以便能够命中cluster-ip ,因为cluster-ip只能在集群内访问。

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

相关问题 nginx入口Pod分配主机的IP地址 - nginx ingress pod assigning IP address of host 我可以在 Kubernetes Ingress 中使用 ip 地址代替域名吗? - Can I use ip address in Kubernetes Ingress instead of domain name? ingress-nginx没有IP地址 - ingress-nginx No IP Address 将Nginx入口绑定到静态IP地址 - Bind nginx-ingress to static IP Address Kubernetes:Nginx Ingress不提供外部IP地址 - Kubernetes: Nginx Ingress not providing external IP address 如何使用服务 IP 地址在 Kubernetes 代替 POD IP 地址 - how to use service IP address at Kubernetes instead of POD IP address 使用 Kubernetes Python 客户端获取 Ingress 网关 IP 地址 - Get Ingress gateway IP address using Kubernetes Python client nginx 在 kuberentes 上的入口看到节点 ip 地址而不是公共 inte.net 资源请求者 - nginx ingress on kuberentes sees node ip address instead of the public internet resource requestor 在不设置 externalTrafficPolicy=Local 的情况下保留客户端 IP 地址,使用 nginx 入口控制器进行进一步的 IP 白名单 - Preserve client IP address without setting externalTrafficPolicy=Local using nginx ingress controller for further IP whitelisting 如何使用本地 IP 地址或 Pod 的主机名从一个 Pod 连接到另一个 - How to connect from one Pod to another using Local IP Address or Pod's host name
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM