简体   繁体   English

Kubernetes 带入口的反向代理

[英]Kubernetes Reverse proxy with Ingress

I have to create an ingress as a reverse proxy to change the port used to call my external service.我必须创建一个入口作为反向代理来更改用于调用我的外部服务的端口。 I have to use an Ingress because the LoadBalancer doesn't work on my local K8 cluster.我必须使用 Ingress,因为 LoadBalancer 在我的本地 K8 集群上不起作用。

External Service外部服务

apiVersion: v1
kind: Service
metadata:
  name: extService
spec:
  type: ExternalName
  externalName: ext.serv.com

In my code, I have a hard-coded configuration that always uses port 8280 for extService calls.在我的代码中,我有一个硬编码配置,始终使用端口 8280 进行 extService 调用。 However, from my local cluster, I have to call extService with port 443但是,从我的本地集群中,我必须使用端口 443 调用 extService

I develop the following Ingress我开发了以下Ingress

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: optcore-ingress
  annotations:
    kubernetes.io/ingress.class: nginx-ingress
spec:
  rules:
    - host: extSrvice
      http:
        paths:
          - path: /
            backend:
              serviceName: optcore
              servicePort: 443

But it doesn't work.但它不起作用。

Well, ExternalName is meant to be used for workloads in your cluster to talk to something 'outside' your cluster.好吧, ExternalName旨在用于集群中的工作负载,以与集群“外部”的事物进行通信。

Essentially, you are hijacking the use of an ExternalName service together with a Kubernetes Ingress resource/nginx ingress controller.本质上,您正在劫持 ExternalName 服务的使用以及 Kubernetes 入口资源/nginx 入口 controller。 So it's likely that it won't work.所以它很可能不会起作用。 Also, an Ingress resource is supposed to work with a service inside your cluster (not outside).此外,Ingress 资源应该与集群内部(而不是外部)的服务一起使用。

If you really want your external service running on 8280 to listen on 443 .如果您真的希望在8280上运行的外部服务能够在443上侦听。 You can set up a regular reverse proxy with nginx, haproxy, etc in front of your service.您可以在您的服务前使用 nginx、haproxy 等设置常规反向代理。

If for some reason you are running your 8280 service inside your cluster (you didn't specify this in your question) you can simply create an 'internal' (regular) service with port 443 and a targetPort of 8280 .如果由于某种原因您在集群内运行8280服务(您没有在问题中指定此内容),您可以简单地创建一个具有端口443targetPort的“内部”(常规)服务8280

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM