方法1:(不建议使用,/etc/resolv.conf不建议修改,有可能引起dns异常)

  • 处理过程:
1,修改宿主机 /etc/resolv.conf文件,添加相关域名

coredns会映射该文件

2,修改/etc/hosts文件,添加该域名解析

方法2:

1,/etc/hosts 添加相关的域名解析
xx.xx.xx.xx harbor.hly.com

2,修改coredns configmap,添加hosts语段:

# kubectl get cm coredns -n kube-system -o yaml
apiVersion: v1
data:
  Corefile: |
    .:53 {
        errors
        health {
            lameduck 5s
        }
        ready
        kubernetes cluster.local in-addr.arpa ip6.arpa {
            pods insecure
            fallthrough in-addr.arpa ip6.arpa
        }
        ## 主要为以下内容(注意末尾添加 .cluster.local):
        ## hosts内部可以添加多个域名
        hosts {
          xx.xx.xx.xx harbor.hly.com.cluster.local
          fallthrough
        }
        prometheus :9153
        forward . /etc/resolv.conf {
            prefer_udp
        }

3,添加后,如果pod内仍无法ping通域名,可以删除coredns pod,重新加载cm文件

# kubectl get pods -A|grep coredns
kube-system                    coredns-6b55b6764d-7wdsq                                          1/1     Running     1          18h
kube-system                    coredns-6b55b6764d-d4q72                                          1/1     Running     1          18h

# kubectl delete pod coredns-6b55b6764d-7wdsq -n kube-system
# kubectl delete pod coredns-6b55b6764d-d4q72 -n kube-system

4,测试
kubectl run -i --tty --image busybox:1.28.4 dns-test --restart=Never --rm /bin/sh

$ nslookup harbor.hly.com.svc (域名后加service名字)

 参考文档:

https://www.cnblogs.com/lbjstill/p/13298826.html

https://kubesphere.com.cn/forum/d/934-coredns/26

GitHub 加速计划 / ha / harbor
23.24 K
4.67 K
下载
Harbor 是一个开源的容器镜像仓库,用于存储和管理 Docker 镜像和其他容器镜像。 * 容器镜像仓库、存储和管理 Docker 镜像和其他容器镜像 * 有什么特点:支持多种镜像格式、易于使用、安全性和访问控制
最近提交(Master分支:1 个月前 )
c5d26723 chore(deps): bump github.com/go-openapi/runtime in /src Bumps [github.com/go-openapi/runtime](https://github.com/go-openapi/runtime) from 0.26.2 to 0.28.0. - [Release notes](https://github.com/go-openapi/runtime/releases) - [Commits](https://github.com/go-openapi/runtime/compare/v0.26.2...v0.28.0) --- updated-dependencies: - dependency-name: github.com/go-openapi/runtime dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: miner <yminer@vmware.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Shengwen YU <yshengwen@vmware.com> Co-authored-by: miner <yminer@vmware.com> 14 天前
76624373 chore(deps): bump github.com/coreos/go-oidc/v3 in /src Bumps [github.com/coreos/go-oidc/v3](https://github.com/coreos/go-oidc) from 3.10.0 to 3.11.0. - [Release notes](https://github.com/coreos/go-oidc/releases) - [Commits](https://github.com/coreos/go-oidc/compare/v3.10.0...v3.11.0) --- updated-dependencies: - dependency-name: github.com/coreos/go-oidc/v3 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Shengwen YU <yshengwen@vmware.com> Co-authored-by: miner <yminer@vmware.com> 14 天前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐