ExternalName服务在DNS中不可见

ExternalName服务在DNS中不可见

本文介绍了Kubernetes ExternalName服务在DNS中不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在两个Kubernetes命名空间中将单个数据库实例作为服务公开.在Ubuntu 16.04.1.上运行的Kubernetes版本1.11.3数据库服务是可见的,并且可以在默认名称空间中使用.我在非默认名称空间中创建了一个外部名称服务,该服务引用默认名称空间中的完全限定域名,如下所示:

I'm trying to expose a single database instance as a service in two Kubernetes namespaces. Kubernetes version 1.11.3 running on Ubuntu 16.04.1. The database service is visible and working in the default namespace. I created an ExternalName service in a non-default namespace referencing the fully qualified domain name in the default namespace as follows:

kind: Service
apiVersion: v1
metadata:
  name: ws-mysql
  namespace: wittlesouth
spec:
  type: ExternalName
  externalName: mysql.default.svc.cluster.local
  ports:
  - port: 3306

服务正在运行:

eric$ kubectl describe service ws-mysql --namespace=wittlesouth
Name:              ws-mysql
Namespace:         wittlesouth
Labels:            <none>
Annotations:       <none>
Selector:          <none>
Type:              ExternalName
IP:
External Name:     mysql.default.svc.cluster.local
Port:              <unset>  3306/TCP
TargetPort:        3306/TCP
Endpoints:         <none>
Session Affinity:  None
Events:            <none>

如果我检查是否可以从在wittlesouth命名空间中运行的pod中通过名称找到该服务,则该服务名称无法解析,但是该命名空间中的其他服务(即Jira)可以:

If I check whether the service can be found by name from a pod running in the wittlesouth namespace, this service name does not resolve, but other services in that namespace (i.e. Jira) do:

root@rs-ws-diags-8mgqq:/# nslookup mysql.default.svc.cluster.local
Server:     10.96.0.10
Address:    10.96.0.10#53

Name:   mysql.default.svc.cluster.local
Address: 10.99.120.208

root@rs-ws-diags-8mgqq:/# nslookup ws-mysql.wittlesouth
Server:     10.96.0.10
Address:    10.96.0.10#53

*** Can't find ws-mysql.wittlesouth: No answer

root@rs-ws-diags-8mgqq:/# nslookup ws-mysql
Server:     10.96.0.10
Address:    10.96.0.10#53

*** Can't find ws-mysql: No answer

root@rs-ws-diags-8mgqq:/# nslookup ws-mysql.wittlesouth
Server:     10.96.0.10
Address:    10.96.0.10#53

*** Can't find ws-mysql.wittlesouth: No answer

root@rs-ws-diags-8mgqq:/# nslookup ws-mysql.wittlesouth.svc.cluster.local
Server:     10.96.0.10
Address:    10.96.0.10#53

*** Can't find ws-mysql.wittlesouth.svc.cluster.local: No answer

root@rs-ws-diags-8mgqq:/# nslookup ws-mysql.wittlesouth
Server:     10.96.0.10
Address:    10.96.0.10#53

*** Can't find ws-mysql.wittlesouth: No answer

root@rs-ws-diags-8mgqq:/# nslookup jira.wittlesouth
Server:     10.96.0.10
Address:    10.96.0.10#53

Name:   jira.wittlesouth.svc.cluster.local
Address: 10.105.30.239

对这里可能存在的问题有任何想法吗?目前,我通过更新需要使用数据库来引用在默认名称空间中运行的服务的完全限定域名的应用程序来解决此问题,但我希望避免这种情况.我的最终目的是让命名空间具有单独的数据库实例,并希望在实际站起来第二个实例之前部署配置为现在可以以这种方式工作的应用程序.

Any thoughts on what might be the issue here? For the moment I've worked around it by updating applications that need to use the database to reference the fully qualified domain name of the service running in the default namespace, but I'd prefer to avoid that. My intent eventually is to have the namespaces have separate database instances, and would like to deploy apps configured to work that way now in advance of actually standing up the second instance.

推荐答案

在带有coredns和calico的Kubernetes 1.11.2中,这不适用于我.仅当您在外部运行的任何命名空间中直接引用外部服务时,它才起作用:

This doesn't work for me with Kubernetes 1.11.2 with coredns and calico. It works only if you reference the external service directly in whichever namespace it runs:

$ kubectl get pods -n default
NAME      READY     STATUS    RESTARTS   AGE
mysql-0   2/2       Running   0          17m
mysql-1   2/2       Running   0          16m

$ kubectl get pods -n wittlesouth
NAME              READY     STATUS    RESTARTS   AGE
ricos-dummy-pod   1/1       Running   0          14s

kubectl exec -it ricos-dummy-pod -n wittlesouth bash
root@ricos-dummy-pod:/# ping mysql.default.svc.cluster.local
PING mysql.default.svc.cluster.local (192.168.1.40): 56 data bytes
64 bytes from 192.168.1.40: icmp_seq=0 ttl=62 time=0.578 ms
64 bytes from 192.168.1.40: icmp_seq=1 ttl=62 time=0.632 ms
64 bytes from 192.168.1.40: icmp_seq=2 ttl=62 time=0.628 ms
^C--- mysql.default.svc.cluster.local ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.578/0.613/0.632/0.025 ms
root@ricos-dummy-pod:/# ping ws-mysql
ping: unknown host
root@ricos-dummy-pod:/# exit

$ kubectl get svc mysql
NAME      TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)    AGE
mysql     ClusterIP   None         <none>        3306/TCP   45d

$ kubectl describe svc mysql
Name:              mysql
Namespace:         default
Labels:            app=mysql
Annotations:       <none>
Selector:          app=mysql
Type:              ClusterIP
IP:                None
Port:              mysql  3306/TCP
TargetPort:        3306/TCP
Endpoints:         192.168.1.40:3306,192.168.2.25:3306
Session Affinity:  None
Events:            <none>

ExternalName服务功能仅受 docs 和Kubernetes 1.11的kube-dn支持. .x默认为coredns.您可能想尝试从coredns更改为kube-dns,或者可能为您的coredns部署更改配置 .我希望可以使用coredns在某些时候使用它.

The ExternalName service feature is only supported using kube-dns as per the docs and Kubernetes 1.11.x defaults to coredns. You might want to try changing from coredns to kube-dns or possibly changing the configs for your coredns deployment. I expect this to available at some point using coredns.

这篇关于Kubernetes ExternalName服务在DNS中不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 20:14