# [FAQ] 物理机上使用 Lightning 可执行文件向 k8s 上 tidb 集群导数据报错 ErrClientCreateTSOStream

## Key Words

物理机, 外部导入,Lightning,ErrClientCreateTSOStream,no such host

## Description

1. 在物理机上使用 Lightning 可执行文件向 k8s 上 tidb 集群,导数据报错 ErrClientCreateTSOStream，具体报错参考下述代码块。
2. 已将 Lightning 需要用到的端口，在 k8s 集群上均暴露给外部，且在物理机测试可正常联通。

    ```shell
    % tiup tidb-lightning -c ./lightning-config.toml --log-file ./lightning.log
    tiup is checking updates for component tidb-lightning ...
    Starting component `tidb-lightning`: /Users/XXX/.tiup/components/tidb-lightning/v6.6.0/tidb-lightning -c ./lightning-config.yaml --log-file ./lightning.log
    Verbose debug logs will be written to ./lightning.log

    {"level":"warn","ts":"2023-03-30T02:20:19.463+0800","logger":"etcd-client","caller":"v3@v3.5.2/retry_interceptor.go:62","msg":"retrying of unary invoker failed","target":"etcd-endpoints://0x14000d78000/XXX:2379","attempt":0,"error":"rpc error: code = DeadlineExceeded desc = latest balancer error: last connection error: connection error: desc = \"transport: Error while dialing dial tcp: lookup XXX.tidb-cluster.svc: no such host\""}
    {"level":"info","ts":"2023-03-30T02:20:19.464+0800","logger":"etcd-client","caller":"v3@v3.5.2/client.go:207","msg":"Auto sync endpoints failed.","error":"context deadline exceeded"}
    tidb lightning encountered error: [Lightning:KV:ErrCreateKVClient]create kv client error: [PD:client:ErrClientCreateTSOStream]create TSO stream failed, retry timeout
    ```

## Content

1. 从报错看是由于获取 TSO 的时候访问 PD leader 返回了 k8s 的内部域名，Lightning 所在的机器无法解析进而报错，即：```connection error: desc = \"transport: Error while dialing dial tcp: lookup XXX.tidb-cluster.svc: no such host```。
2. 该问题是由于 TiDB 官方更推荐在 k8s 集训内部部署 Lightning，并未适配在 k8s 外部直接使用的方式导入数据，详情参考官网[链接](https://docs.pingcap.com/tidb-in-kubernetes/stable/restore-data-using-tidb-lightning)。
3. 绕过方式：除了暴露必要端口并在 config 文件中手动指定 PD 地址外，还需在 Lightning 所在机器的 hosts 文件中添加了**所有需要的 svc 节点的域名解析**。示例如下：

    ```shell
    % cat /etc/hosts
    ...
    DNS-IP XXX-pd-peer.tidb-cluster.svc
    ...
    ```

## Affected Versions

ALL
