Service DNS-based practice of multi-cluster External-DNS

Outline

External-DNS provides DNS resource management Kubernetes Service programming mode feature, similar to container services kubernetes federation v2 a practice: Practice-based multi Ingress DNS cluster of External-DNS , External-DNS listens LoadBalancer type of Service, then the cloud manufacturers get through, generating its own domain name in accordance with the available area, region and global analytical record three dimensions, easy to direct traffic between service calls. This paper briefly describes how to use External-DNS management on Ali cloud platform multi-cluster container Service DNS.

Preparing the Environment

Reference container service kubernetes federation v2 a practice: Practice-based multi Ingress DNS cluster External-DNS is completed [Federal clusters ready], [information] and [RAM configuration deployment External-DNS] section, and configured kubeConfig, as follows:

kubectl config get-contexts
CURRENT   NAME       CLUSTER    AUTHINFO            NAMESPACE
*         cluster1   cluster1   kubernetes-admin1
          cluster2   cluster2   kubernetes-admin2

Resource deployment

Creating FederatedDeployment and FederatedService

yaml follows, note type FederatedService LoadBalancer

apiVersion: v1
kind: Namespace
metadata:
  name: test-namespace

---

apiVersion: types.federation.k8s.io/v1alpha1
kind: FederatedNamespace
metadata:
  name: test-namespace
  namespace: test-namespace
spec:
  placement:
    clusterNames:
    - cluster1
    - cluster2

---

apiVersion: types.federation.k8s.io/v1alpha1
kind: FederatedDeployment
metadata:
  name: test-deployment
  namespace: test-namespace
spec:
  template:
    metadata:
      labels:
        app: nginx
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - image: nginx
            name: nginx
  placement:
    clusterNames:
    - cluster1
    - cluster2
    
---

apiVersion: types.federation.k8s.io/v1alpha1
kind: FederatedService
metadata:
  name: test-service
  namespace: test-namespace
spec:
  template:
    spec:
      selector:
        app: nginx
      type: LoadBalancer
      ports:
        - name: http
          port: 80
  placement:
    clusterNames:
    - cluster2
    - cluster1

Check each cluster Service Details:

get svc -n test-namespace --context cluster1
NAME           TYPE           CLUSTER-IP     EXTERNAL-IP    PORT(S)        AGE
test-service   LoadBalancer   172.23.5.173   39.96.243.59   80:30185/TCP   28s

get svc -n test-namespace --context cluster2
NAME           TYPE           CLUSTER-IP     EXTERNAL-IP    PORT(S)        AGE
test-service   LoadBalancer   172.21.11.44   47.95.152.65   80:30384/TCP   31s

Creating Domain and ServiceDNSRecord

yaml below, please note] [service.example-domain.club replaced by a test domain name (domain name must be cloud-hosted by the Ali).

apiVersion: multiclusterdns.federation.k8s.io/v1alpha1
kind: Domain
metadata:
  name: test-domain
  namespace: federation-system
domain: service.example-domain.club
---
apiVersion: multiclusterdns.federation.k8s.io/v1alpha1
kind: ServiceDNSRecord
metadata:
  name: test-service
  namespace: test-namespace
spec:
  domainRef: test-domain
  recordTTL: 600

Result analysis

View DnsEndpoint details:

kubectl get dnsendpoint -n test-namespace -o yaml
apiVersion: v1
items:
- apiVersion: multiclusterdns.federation.k8s.io/v1alpha1
  kind: DNSEndpoint
  metadata:
    creationTimestamp: 2019-05-17T08:49:31Z
    generation: 2
    name: service-test-service
    namespace: test-namespace
    resourceVersion: "742339863"
    selfLink: /apis/multiclusterdns.federation.k8s.io/v1alpha1/namespaces/test-namespace/dnsendpoints/service-test-service
    uid: afd3e22a-7880-11e9-9566-326dc52c25d3
  spec:
    endpoints:
    - dnsName: test-service.test-namespace.test-domain.svc.cn-beijing-a.cn-beijing.service.example-domain.club
      recordTTL: 600
      recordType: A
      targets:
      - 47.95.152.65
    - dnsName: test-service.test-namespace.test-domain.svc.cn-beijing-f.cn-beijing.service.example-domain.club
      recordTTL: 600
      recordType: A
      targets:
      - 39.96.243.59
    - dnsName: test-service.test-namespace.test-domain.svc.cn-beijing.service.example-domain.club
      recordTTL: 600
      recordType: A
      targets:
      - 39.96.243.59
      - 47.95.152.65
    - dnsName: test-service.test-namespace.test-domain.svc.service.example-domain.club
      recordTTL: 600
      recordType: A
      targets:
      - 39.96.243.59
      - 47.95.152.65
kind: List
metadata:
  resourceVersion: ""
  selfLink: ""

External-DNS can be seen that has been automatically generated record parsing 4, comprising two available District, Beijing, Beijing region and four global dns resolution recording.

dig +short @dns7.hichina.com test-service.test-namespace.test-domain.svc.cn-beijing-a.cn-beijing.service.example-domain.club
47.95.152.65

dig +short @dns7.hichina.com test-service.test-namespace.test-domain.svc.cn-beijing-f.cn-beijing.service.example-domain.club
39.96.243.59

dig +short @dns7.hichina.com test-service.test-namespace.test-domain.svc.cn-beijing.service.example-domain.club
47.95.152.65
39.96.243.59

dig +short @dns7.hichina.com test-service.test-namespace.test-domain.svc.service.example-domain.club
47.95.152.65
39.96.243.59

in conclusion

External-DNS in the Federation-V2 multi-cluster federal environment, you can generate multiple DNS resolution based on available records of the District Service is deployed, region and global three dimensions, to help direct traffic and flexible service.


Original link
This article Yunqi community original content may not be reproduced without permission.

Guess you like

Origin blog.csdn.net/yunqiinsight/article/details/91960145