Kubernetes 跨命名空间入口网络 [英] Kubernetes Cross Namespace Ingress Network

查看:42
本文介绍了Kubernetes 跨命名空间入口网络的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的入口网络,我想从这个入口网络访问不同命名空间中的服务.

I have a simple ingress network, I want to access services at different namespaces, from this ingress network.

我该怎么做?我的入口网络 yaml 文件:

How I can do this? My ingress network yaml file:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress
spec:
  rules:
 - host: api.myhost.com
 http:
 paths:
  - backend:
      serviceName: bookapi-2
      servicePort: 8080
    path: /booking-service/

我已将 ExternalNames 服务类型设置为 yaml 文件:

I've set the ExternalNames service type to the yaml file:

 apiVersion: v1
 kind: Service
 metadata:
   name: bookapi-2
   namespace: booking-namespace
 spec:
   type: ExternalName
   externalName: bookapi-2
   ports:
     - name: app
     protocol: TCP
      port: 8080
      targetPort: 8080
   selector:
      app: bookapi-2
      tier: backend-2

推荐答案

ExternalName 服务是一种特殊的服务,它不有选择器并使用 DNS 名称.

An ExternalName service is a special case of service that does not have selectors and uses DNS names instead.

您可以从官方 Kubernetes 文档中了解有关 ExternalName 服务的更多信息:

当您想从不同的命名空间访问服务时,您的 yaml 可以,例如 example,看起来像这样:

When you want to access a service from a different namespace, your yaml could, for example, look like this:

kind: Service
apiVersion: v1
metadata:
  name: test-service-1
  namespace: namespace-a
spec:
  type: ExternalName
  externalName: test-service-2.namespace-b.svc.cluster.local
  ports:
  - port: 80

至于您的 Ingress yaml 文件,请重新检查并确保它符合官方示例,例如 example 这个因为它包含一些不一致:

As to your Ingress yaml file, please recheck it and make sure it is compliant with the official examples, for example this one as it contains some inconsistency:

apiVersion: extensions/v1beta1  
kind: Ingress  
metadata:  
  name: my-ingress  
spec:  
  rules:  
  - host: www.mysite.com  
    http:  
      paths:  
      - backend:  
          serviceName: website  
          servicePort: 80  
  - host: forums.mysite.com  
    http:  
      paths:  
      - path:  
        backend:  
          serviceName: forums  
          servicePort: 80

还请重新检查 ExternalName yaml,因为它具有未在此类 服务 并确保:

Please also recheck ExternalName yaml as it has TargetPorts and selectors which are not used in this type of Service and make sure that:

ExternalName 服务仅适用于 kube-dns 1.7 版及以后.

ExternalName Services are available only with kube-dns version 1.7 and later.

如果您不会成功,请分享您遇到的问题.

In case you will not succeed, please share the kind of problem you have meet.

这篇关于Kubernetes 跨命名空间入口网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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