(Kops) Kubernetes Service maped to DNS names in AWS Route53?

梦想与她 提交于 2019-12-23 00:52:19

问题


I am new to Kops and a bit to kubernetes as well. I managed to create a cluster with Kops, and run a deployment and a service on it. everything went well, and an ELB was created for me and I could access the application via this ELB endpoint.

My question is: How can I map my subdomain (eg. my-sub.example.com) to the generated ELB endpoint ? I believe this should be somehow done automatic by kubernetes and I should not hardcode the ELB endpoint inside my code. I tried something that has to do with annotation -> DomainName, but it did not work.(see kubernetes yml file below)

apiVersion: v1
kind: Service
metadata:
  name: django-app-service
  labels:
    role: web
    dns: route53
  annotations:
    domainName: "my.personal-site.de"
spec:
  type: LoadBalancer
  selector:
    app: django-app
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8000

----

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: django-app-deployment
spec:
  replicas: 2
  minReadySeconds: 15
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
  template:
    metadata:
      labels:
        app: django-app
    spec:
      containers:
        - image: fettah/djano_kubernetes_medium:latest
          name:  django-app
          imagePullPolicy: Always
          ports:
            - containerPort: 8000

回答1:


When you have ELBs in place you can use external-dns (https://github.com/kubernetes-incubator/external-dns) plugin which can attach DNS records to those ELBs using AWS Route53 integration. You need to add proper rights to Kubernetes so he can create DNS record in Route53 - you need to add additional policy in kops (according guide in external-dns plugin) in additionalPolicies section in kops cluster configuration. Then use annotation like:

external-dns.alpha.kubernetes.io/hostname: myservice.mydomain.com.


来源:https://stackoverflow.com/questions/52356819/kops-kubernetes-service-maped-to-dns-names-in-aws-route53

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!