Kubernetes进入外部服务? [英] Kubernetes Ingress to External Service?

查看:55
本文介绍了Kubernetes进入外部服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个不在Kubernetes上托管的服务.我还在kubernetes集群上设置了一个入口控制器和证书管理器.

Say I have a service that isn't hosted on Kubernetes. I also have an ingress controller and cert-manager set up on my kubernetes cluster.

因为使用kubernetes入口来控制对服务的访问是如此简单和容易,所以我想拥有一个指向非kubernetes服务的kubernetes入口.

Because it's so much simpler and easy to use kubernetes ingress to control access to services, I wanted to have a kubernetes ingress that points to a non-kubernetes service.

例如,我有一个托管在https://10.0.40.1:5678的服务(需要SSL,但具有自签名证书),并且想要访问service.example.com.

For example, I have a service that's hosted at https://10.0.40.1:5678 (ssl required, but self signed certificate) and want to access at service.example.com.

推荐答案

可以通过为外部服务器手动创建Service和Endpoint对象来实现.

You can do it by manual creation of Service and Endpoint objects for your external server.

对象看起来像这样:

apiVersion: v1
kind: Service
metadata:
  name: external-ip
spec:
  ports:
  - name: app
    port: 80
    protocol: TCP
    targetPort: 5678
  clusterIP: None
  type: ClusterIP
---
apiVersion: v1
kind: Endpoints
metadata:
  name: external-ip
subsets:
- addresses:
  - ip: 10.0.40.1
  ports:
  - name: app
    port: 5678
    protocol: TCP

然后,您可以创建一个Ingress对象,该对象将通过端口80指向服务external-ip:

Then, you can create an Ingress object which will point to Service external-ip with port 80:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: external-service
spec:
  rules:
  - host: service.example.com
    http:
      paths:
      - backend:
          serviceName: external-ip
          servicePort: 80
        path: /

这篇关于Kubernetes进入外部服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆