Istio 访问 ServiceEntry host 无法解析

场景:现在有一个 httpbin 服务直接通过 service entry 注册到网格内部,但是使用确无法解析到域名,下面是实际的错。现在就要解决问题

/ # curl httpbin.remote:30655/ip
curl: (6) Could not resolve host: httpbin.remote

首先检查有没有配置 DNS

apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
spec:
  meshConfig:
    defaultConfig:
      proxyMetadata:
        # Enable basic DNS proxying
        ISTIO_META_DNS_CAPTURE: "true"
        # Enable automatic address allocation, optional
        ISTIO_META_DNS_AUTO_ALLOCATE: "true"

我检查发现已经配置了 dns,这一步就排除了

然后检查 DNS 服务是否正常,这里简单说明一下:istio 的高版本使用的是 smart DNS,而低版本指的是 1.8 以前的版本使用的是 istio coredns,这里我使用的就是 istio coredns,所以直接查看 coredns 状态。

# kubectl get pod -n istio-system -l app=istiocoredns
NAME                            READY   STATUS    RESTARTS   AGE
istiocoredns-84867bdf54-v8vbb   2/2     Running   0          51d

dns pod 现在正在运行,那么我们现在通过日志查询 dns 服务是否正常运行

# kubectl logs -f istiocoredns-84867bdf54-v8vbb -n istio-system -c istio-coredns-plugin --tail 100
unknown field "workloadSelector" in v1alpha3.ServiceEntry map[addresses:[240.0.0.2] hosts:[vm-t.vm.svc.cluster.local] location:MESH_INTERNAL ports:[map[name:http-http-8000 number:8000 protocol:http]] resolution:STATIC workloadSelector:map[labels:map[service.istio.io/canonical-revision:v1 version_mesh:v1 app_mesh:vm-t bocloud.com.cn/vm:true service.istio.io/canonical-name:vm-t]]]
unknown field "workloadSelector" in v1alpha3.ServiceEntry map[addresses:[240.0.0.2] hosts:[vm-t.vm.svc.cluster.local] location:MESH_INTERNAL ports:[map[name:http-http-8000 number:8000 protocol:http]] resolution:STATIC workloadSelector:map[labels:map[service.istio.io/canonical-name:vm-t service.istio.io/canonical-revision:v1 version_mesh:v1 app_mesh:vm-t bocloud.com.cn/vm:true]]]
unknown field "targetPort" in v1alpha3.Port map[location:MESH_INTERNAL ports:[map[targetPort:15443 name:http-9080 number:9080 protocol:HTTP]] resolution:DNS hosts:[productpage.pyqns.svc.cluster.local]]
2022-03-08T05:55:02.752127Z error Failed to convert service-entry object, ignoring: vm/vm-test YAML decoding error: addresses:
2022-03-08T06:44:22.762466Z	info	Have 7 service entries
2022-03-08T06:44:22.762609Z	info	adding DNS mapping: productpage.bookinfo-test.global.->[240.0.0.8]
2022-03-08T06:44:22.762618Z	info	adding DNS mapping: reviews.bookinfo-test.global.->[240.0.0.9]
2022-03-08T06:44:22.762624Z	info	adding DNS mapping: http.app.->[240.0.0.100]
2022-03-08T06:44:22.762631Z	info	adding DNS mapping: details.bookinfo-test.global.->[240.0.0.6]
2022-03-08T06:44:22.762637Z	info	adding DNS mapping: ratings.bookinfo-test.global.->[240.0.0.7]
2022-03-08T06:44:27.761222Z	info	Reading service entries at 2022-03-08 06:44:27.761157157 +0000 UTC m=+4319335.422405709

从日志可以很明显看出问题
1: 错误的 serviceentry 使用了workloadSelector、targetPort 字段,但是当前的 istio 版本并不支持
2: 有的 service entry 使用了 addresses 导致编码失败
3: Have 7 service entries 证明我们存在了 7 个 service entrie,但是实际确只有 5 个 service entrie 分配了 ip 地址,也就是说还有一个 service entry 存在无法解析 host 的问题

debug 一直进行到这里,问题就已经相当明朗了,针对上面的问题一一解决

  • 问题 1: 直接删除使用了 workloadSelector、targetPort 的 service entry,是因为使用了高版本的 istio 重新部署之后没有删除 service entry 而导致的
  • 问题 2: 查看 address 时候符合规范,重新分配 ip 地址即可
  • 最重要的问题 3,目前最主要的问题,没有为 host 分配 ip,因为在 iop 里面配置了 ISTIO_META_DNS_AUTO_ALLOCATE 这个参数可以帮助我们自动分配 ip,所以我没有在 service entry 中明确配置 address 字段。从而导致了这个问题。现在添加一下 address 然后查询日志
spec:
  addresses:
  - 240.0.0.88
  endpoints:
  - address: 10.20.21.20
    ports:
      http-10: 30655
  hosts:
  - httpbin.remote
  location: MESH_INTERNAL
  ports:
  - name: http-10
    number: 8100
    protocol: http
  resolution: DNS

查询日志

2022-03-08T07:05:32.749801Z	info	Reading service entries at 2022-03-08 07:05:32.749760496 +0000 UTC m=+4320600.411009043
2022-03-08T07:05:32.752280Z	info	Have 7 service entries
2022-03-08T07:05:32.752383Z	info	adding DNS mapping: details.bookinfo-test.global.->[240.0.0.6]
2022-03-08T07:05:32.752408Z	info	adding DNS mapping: ratings.bookinfo-test.global.->[240.0.0.7]
2022-03-08T07:05:32.752413Z	info	adding DNS mapping: http.app.->[240.0.0.100]
2022-03-08T07:05:32.752418Z	info	adding DNS mapping: httpbin.remote.->[240.0.0.88]
2022-03-08T07:05:32.752423Z	info	adding DNS mapping: productpage.bookinfo-test.global.->[240.0.0.8]
2022-03-08T07:05:32.752428Z	info	adding DNS mapping: reviews.bookinfo-test.global.->[240.0.0.9]
2022-03-08T07:05:37.749806Z	info	Reading service entries at 2022-03-08 07:05:37.749761643 +0000 UTC m=+4320605.411010374

果然,现在查询日志就可以看到 httpbin.remote 映射的 ip 240.0.0.88 已经被添加到 DNS 中。

然后再次访问 host

/ # curl httpbin.remote:30655/ip
{
  "origin": "10.20.21.20"
}

至于 ISTIO_META_DNS_AUTO_ALLOCATE 参数没有生效,就有待研究了,也可能只在 1.8.4 版本不生效罢了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值