External-DNS提供了編程方式管理Kubernetes Ingress資源的DNS的功能,方便用戶從Ingress管理DNS解析記錄。而在kubernetes federation v2環境中,使用External-DNS能夠快速的管理多個聯邦集羣的Ingress DNS解析,下降用戶的操做成本。下面將簡單介紹在阿里雲容器服務環境中,如何使用External-DNS管理聯邦集羣的Ingress DNS解析。html
參考阿里雲Kubernetes容器服務上體驗Federation v2 搭建兩個集羣組成的聯邦集羣(配置好kubeconfig,並完成兩個集羣的join)。node
選擇Kubernetes集羣節點列表內任意一個Worker節點,打開對應的節點列表信息頁面。
找到對應的 RAM 角色,打開RAM控制檯,找到對應的角色名稱,添加【AliyunDNSFullAccess】權限。
注意:每一個集羣都須要配置RAM信息。nginx
執行下面yaml:web
apiVersion: v1 kind: ServiceAccount metadata: name: external-dns --- apiVersion: rbac.authorization.k8s.io/v1beta1 kind: ClusterRole metadata: name: external-dns rules: - apiGroups: [""] resources: ["services"] verbs: ["get","watch","list"] - apiGroups: [""] resources: ["pods"] verbs: ["get","watch","list"] - apiGroups: ["extensions"] resources: ["ingresses"] verbs: ["get","watch","list"] - apiGroups: [""] resources: ["nodes"] verbs: ["list"] - apiGroups: ["multiclusterdns.federation.k8s.io"] resources: ["dnsendpoints"] verbs: ["get", "watch", "list"] --- apiVersion: rbac.authorization.k8s.io/v1beta1 kind: ClusterRoleBinding metadata: name: external-dns-viewer roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: external-dns subjects: - kind: ServiceAccount name: external-dns namespace: default
執行下面yaml:編程
apiVersion: extensions/v1beta1 kind: Deployment metadata: name: external-dns spec: strategy: type: Recreate template: metadata: labels: app: external-dns spec: serviceAccountName: external-dns containers: - name: external-dns image: registry.cn-beijing.aliyuncs.com/acs/external-dns:v0.5.8-27 args: - --source=crd - --crd-source-apiversion=multiclusterdns.federation.k8s.io/v1alpha1 - --crd-source-kind=DNSEndpoint - --provider=alibabacloud - --policy=sync # enable full synchronization - --registry=txt - --txt-prefix=cname - --txt-owner-id=my-identifier - --alibaba-cloud-config-file= # enable sts token volumeMounts: - mountPath: /usr/share/zoneinfo name: hostpath volumes: - name: hostpath hostPath: path: /usr/share/zoneinfo type: Directory
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 resources: limits: cpu: 500m requests: cpu: 200m 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: ClusterIP ports: - name: http port: 80 placement: clusterNames: - cluster2 - cluster1
各個集羣ingress建立信息以下:api
kubectl get ingress -n test-namespace --context cluster1 NAME HOSTS ADDRESS PORTS AGE test-ingress * 47.93.69.121 80 54m kubectl get ingress -n test-namespace --context cluster2 NAME HOSTS ADDRESS PORTS AGE test-ingress * 39.106.232.23 80 54m
apiVersion: types.federation.k8s.io/v1alpha1 kind: FederatedIngress metadata: name: test-ingress namespace: test-namespace spec: template: spec: backend: serviceName: test-service servicePort: 80 placement: clusterNames: - cluster2 - cluster1 --- apiVersion: multiclusterdns.federation.k8s.io/v1alpha1 kind: IngressDNSRecord metadata: name: test-ingress namespace: test-namespace spec: hosts: - ingress-example.example-domain.club recordTTL: 600
其中【ingress-example.example-domain.club】爲測試阿里雲託管的域名,請提早在阿里雲上購買域名,並注意替換。app
dig +short @dns7.hichina.com ingress-example.example-domain.club 47.93.69.121 39.106.232.23
能夠看到咱們綁定的域名已經解析到了cluster1和cluster2的ingress IP上了。
訪問域名相應的服務:dom
curl ingress-example.sigma-host.club <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>
經過上面介紹,能夠看到使用External-DNS能夠很是方便的管理federation-v2環境下的Ingress DNS解析。curl
原文連接
本文爲雲棲社區原創內容,未經容許不得轉載。ide