联邦DNS安装

前置条件

  • 准备好一个集群联邦,本文将在《集群联邦》一文中搭建好的环境,有f-cluster作为宿主集群,有a-clusterb-cluster作为两个工作集群

  • a-clusterb-cluster中安装好metallb,安装教程参考《安装MetalLB》;a-clustermetallb使用的address范围为192.168.2.110-120b-clustermetallb使用的address范围为192.168.2.210-220

  • 本文要继续参考v0.0.10版本的文档,除非有些页面该版本的文档不存在

安装etcd集群

CoreDNSExternalDNS共用一个etcd集群,该集群的数据最好能持久化。假设安装好后,etcd集群的地址为192.168.2.103:3379

安装CoreDNS

下载values.yaml文件

wget https://raw.githubusercontent.com/helm/charts/master/stable/coredns/values.yaml

更改其中的内容(版本不同该文件的原始内容可能会有变化,下面给出最终状态)

  • serviceAccount.create最后要为false

  • rbac.create最后要为true

  • isClusterService最后要为false

  • servers.plugins中要添加如下内容

- name: etcd
  parameters: example.com
  configBlock: |-
    stubzones
    path /skydns
    endpoint http://192.168.2.103:3379

然后执行以下命令安装

$ helm install --name my-coredns --values values.yaml stable/coredns

安装ExternalDNS

在宿主集群中创建以下的资源以安装ExternalDNS,注意github上的参考文档master分支中这一行的原内容为--crd-source-apiversion=multiclusterdns.kubefed.k8s.io/v1alpha1,但如果

创建Service

创建一个FederatedService,类型为LoadBalancer

创建好之后,我们可以在a-clusterb-cluster有命名空间test-namespace中都可以看到一个名字为test-serviceService

$ kubectl get service -n test-namespace --context a-context
NAME           TYPE           CLUSTER-IP       EXTERNAL-IP     PORT(S)        AGE
test-service   LoadBalancer   10.102.103.116   192.168.2.110   80:31615/TCP   113s

$ kubectl get service -n test-namespace --context b-context
NAME           TYPE           CLUSTER-IP       EXTERNAL-IP     PORT(S)        AGE
test-service   LoadBalancer   10.108.248.125   192.168.2.210   80:30052/TCP   139s

然后为这个FederatedService创建一个DNS记录

查询DNS记录

过几分钟后,去CoreDNS查询刚刚创建的FederatedSerivce的DNS记录。在这里,DNS服务器就是my-coredns-coredns

$ kubectl get service my-coredns-coredns
NAME                 TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)         AGE
my-coredns-coredns   ClusterIP   10.100.112.235   <none>        53/UDP,53/TCP   38m

$ kubectl run -it --rm --restart=Never --image=infoblox/dnstools:latest dnstools
dnstools# dig @10.100.112.235 test-service.test-namespace.test-domain.svc.example.com +short

Last updated

Was this helpful?