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

查看:76
本文介绍了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文档中找到有关外部名称服务的更多信息:

当您想从其他名称空间访问服务时,您的Yaml可以示例,如下所示:

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文件,请重新检查并确保它与官方示例兼容,例如

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,因为它具有TargetPorts和选择器,而在

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

外部名称服务仅在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天全站免登陆