本文介绍了如何将kubernetes LoadBalancer入口URL发布到AWS Route53的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,当我在aws上使用kubernetes启动应用程序时,它公开了一个公开可见的LoadBalancer入口URL,但是要将其链接到我的域以使该应用程序对公众可用,我需要手动进入aws route53控制台浏览器每次启动时.我可以通过命令行更新aws route53资源类型A以匹配最新的Kubernetes LoadBalancer入口URL吗?

基于gcloud的Kubernetes面临着这一挑战,即必须预定义启动配置中使用的静态IP,或者在启动后手动执行基于浏览器的域链接.在aws上,我希望可以从命令行

使用与此类似的内容

aws route53domains update-domain-nameservers   ???

__或__我可以预定义aws kubernetes LoadBalancer Ingress,类似于通过gcloud进行预定义的静态IP吗?

显示已部署的应用程序的LoadBalancer入口URL问题

kubectl describe svc

...输出

Name:           aaa-deployment-407
Namespace:      ruptureofthemundaneplane
Labels:         app=bbb
            pod-template-hash=4076262206
Selector:       app=bbb,pod-template-hash=4076262206
Type:           LoadBalancer
IP:         10.0.51.82
LoadBalancer Ingress:   a244bodhisattva79c17cf7-61619.us-east-1.elb.amazonaws.com
Port:           port-1  80/TCP
NodePort:       port-1  32547/TCP
Endpoints:      10.201.0.3:80
Port:           port-2  443/TCP
NodePort:       port-2  31248/TCP
Endpoints:      10.201.0.3:443
Session Affinity:   None
No events.

更新:

尝试新的命令行技术时遇到错误(@ error2007s注释的提示)...发出此

aws route53 list-hosted-zones

...输出

{
    "HostedZones": [
        {
            "ResourceRecordSetCount": 6,
            "CallerReference": "2D58A764-1FAC-DEB4-8AC7-AD37E74B94E6",
            "Config": {
                "PrivateZone": false
            },
            "Id": "/hostedzone/Z3II3949ZDMDXV",
            "Name": "chainsawhaircut.com."
        }
    ]
}

下面使用的重要位:托管区域Z3II3949ZDMDXV

现在我可以使用此文档遵循 ="http://docs.aws.amazon.com/cli/latest/reference/route53/change-resource-record-sets.html" rel ="noreferrer">(以及此文档)文件/change-resource-record-sets.json(注意,我可以使用类似的cli调用成功更改Type A ...但是我需要使用LoadBalancer Ingress URL的别名目标来更改Type A)

{
    "Comment": "Update record to reflect new IP address of fresh deploy",
    "Changes": [{
        "Action": "UPSERT",
        "ResourceRecordSet": {
            "Name": "chainsawhaircut.com.",
            "Type": "A",
            "TTL": 60,
            "AliasTarget": {
                "HostedZoneId": "Z3II3949ZDMDXV",
                "DNSName": "a244bodhisattva79c17cf7-61619.us-east-1.elb.amazonaws.com",
                "EvaluateTargetHealth": false
            }
        }
    }]
}

然后在命令行上发布

aws route53 change-resource-record-sets --hosted-zone-id Z3II3949ZDMDXV --change-batch file:///change-resource-record-sets.json

给出此错误消息

An error occurred (InvalidInput) when calling the ChangeResourceRecordSets operation: Invalid request

有什么见解吗?

解决方案

以下是使用来自刚创建的kubernetes LoadBalancer入口URL的值更新AWS route53资源记录类型A所需的逻辑

步骤1-通过发出标识您的托管区域ID

aws route53 list-hosted-zones

...从这里的输出中是我的域的剪辑

"Id": "/hostedzone/Z3II3949ZDMDXV",

...重要的是,永远不要使用hostedzone Z3II3949ZDMDXV填充json,它仅用作cli parm ...还有另一个名称相似的令牌HostedZoneId,完全不同

第2步-查看您的route53域记录的当前值...问题:

aws route53 list-resource-record-sets --hosted-zone-id Z3II3949ZDMDXV --query "ResourceRecordSets[?Name == 'scottstensland.com.']"

...输出

[
    {
        "AliasTarget": {
            "HostedZoneId": "Z35SXDOTRQ7X7K",
            "EvaluateTargetHealth": false,
            "DNSName": "dualstack.asomepriorvalue39e7db-1867261689.us-east-1.elb.amazonaws.com."
        },
        "Type": "A",
        "Name": "scottstensland.com."
    },
    {
        "ResourceRecords": [
            {
                "Value": "ns-1238.awsdns-26.org."
            },
            {
                "Value": "ns-201.awsdns-25.com."
            },
            {
                "Value": "ns-969.awsdns-57.net."
            },
            {
                "Value": "ns-1823.awsdns-35.co.uk."
            }
        ],
        "Type": "NS",
        "Name": "scottstensland.com.",
        "TTL": 172800
    },
    {
        "ResourceRecords": [
            {
                "Value": "ns-1238.awsdns-26.org. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400"
            }
        ],
        "Type": "SOA",
        "Name": "scottstensland.com.",
        "TTL": 900
    }
]
的上述通知值中的

...

"HostedZoneId": "Z35SXDOTRQ7X7K",

这是第二个类似名称的令牌 请勿使用错误的托管区域ID

步骤3-将以下内容放入更改文件aws_route53_type_A.json (有关语法文档,请参见上面的注释中提到的链接)

{
  "Comment": "Update record to reflect new DNSName of fresh deploy",
  "Changes": [
    {
      "Action": "UPSERT",
      "ResourceRecordSet": {
        "AliasTarget": {
            "HostedZoneId": "Z35SXDOTRQ7X7K",
            "EvaluateTargetHealth": false,
            "DNSName": "dualstack.a0b82c81f47d011e6b98a0a28439e7db-1867261689.us-east-1.elb.amazonaws.com."
        },
        "Type": "A",
        "Name": "scottstensland.com."
      }
    }
  ]
}

要为上面的字段"DNSName"标识值...在kubernetes应用程序部署到AWS上之后,它会以cli命令的输出所示的LoadBalancer Ingress响应:

kubectl describe svc --namespace=ruptureofthemundaneplane

...如

LoadBalancer Ingress:   a0b82c81f47d011e6b98a0a28439e7db-1867261689.us-east-1.elb.amazonaws.com

...即使我的目标是执行命令行调用,也可以通过进入aws控制台浏览器手动完成此操作...在route53上拉起我的域...

...在此浏览器选择列表的可编辑文本框中(绿色圆圈),我注意到URL神奇地加上了:dualstack.以前,我缺少该魔术字符串...因此json键"DNSName"想要此

dualstack.a0b82c81f47d011e6b98a0a28439e7db-1867261689.us-east-1.elb.amazonaws.com.

最终执行更改请求

aws route53 change-resource-record-sets --hosted-zone-id Z3II3949ZDMDXV --change-batch file://./aws_route53_type_A.json

...输出

{
    "ChangeInfo": {
        "Status": "PENDING",
        "Comment": "Update record to reflect new DNSName of fresh deploy",
        "SubmittedAt": "2016-07-13T14:53:02.789Z",
        "Id": "/change/CFUX5R9XKGE1C"
    }
}

....现在确认更改是否实时运行,以显示记录

aws route53  list-resource-record-sets  --hosted-zone-id Z3II3949ZDMDXV

Today when I launch an app using kubernetes over aws it exposes a publicly visible LoadBalancer Ingress URL, however to link that to my domain to make the app accessible to the public, I need to manually go into the aws route53 console in a browser on every launch. Can I update the aws route53 Resource Type A to match the latest Kubernetes LoadBalancer Ingress URL from the command line ?

Kubernetes over gcloud shares this challenge of having to either predefine a Static IP which is used in launch config or manually do a browser based domain linkage post launch. On aws I was hoping I could use something similar to this from the command line

aws route53domains update-domain-nameservers   ???

__ OR __ can I predefine an aws kubernetes LoadBalancer Ingress similar to doing a predefined Static IP when over gcloud ?

to show the deployed app's LoadBalancer Ingress URL issue

kubectl describe svc

... output

Name:           aaa-deployment-407
Namespace:      ruptureofthemundaneplane
Labels:         app=bbb
            pod-template-hash=4076262206
Selector:       app=bbb,pod-template-hash=4076262206
Type:           LoadBalancer
IP:         10.0.51.82
LoadBalancer Ingress:   a244bodhisattva79c17cf7-61619.us-east-1.elb.amazonaws.com
Port:           port-1  80/TCP
NodePort:       port-1  32547/TCP
Endpoints:      10.201.0.3:80
Port:           port-2  443/TCP
NodePort:       port-2  31248/TCP
Endpoints:      10.201.0.3:443
Session Affinity:   None
No events.

UPDATE:

Getting error trying new command line technique (hat tip to @error2007s comment) ... issue this

aws route53 list-hosted-zones

... outputs

{
    "HostedZones": [
        {
            "ResourceRecordSetCount": 6,
            "CallerReference": "2D58A764-1FAC-DEB4-8AC7-AD37E74B94E6",
            "Config": {
                "PrivateZone": false
            },
            "Id": "/hostedzone/Z3II3949ZDMDXV",
            "Name": "chainsawhaircut.com."
        }
    ]
}

Important bit used below : hostedzone Z3II3949ZDMDXV

now I craft following using this Doc (and this Doc as well) as file /change-resource-record-sets.json (NOTE I can successfully change Type A using a similar cli call ... however I need to change Type A with an Alias Target of LoadBalancer Ingress URL)

{
    "Comment": "Update record to reflect new IP address of fresh deploy",
    "Changes": [{
        "Action": "UPSERT",
        "ResourceRecordSet": {
            "Name": "chainsawhaircut.com.",
            "Type": "A",
            "TTL": 60,
            "AliasTarget": {
                "HostedZoneId": "Z3II3949ZDMDXV",
                "DNSName": "a244bodhisattva79c17cf7-61619.us-east-1.elb.amazonaws.com",
                "EvaluateTargetHealth": false
            }
        }
    }]
}

on command line I then issue

aws route53 change-resource-record-sets --hosted-zone-id Z3II3949ZDMDXV --change-batch file:///change-resource-record-sets.json

which give this error message

An error occurred (InvalidInput) when calling the ChangeResourceRecordSets operation: Invalid request

Any insights ?

解决方案

Here is the logic needed to update aws route53 Resource Record Type A with value from freshly minted kubernetes LoadBalancer Ingress URL

step 1 - identify your hostedzone Id by issuing

aws route53 list-hosted-zones

... from output here is clip for my domain

"Id": "/hostedzone/Z3II3949ZDMDXV",

... importantly never populate json with hostedzone Z3II3949ZDMDXV its only used as a cli parm ... there is a second similarly named token HostedZoneId which is entirely different

step 2 - see current value of your route53 domain record ... issue :

aws route53 list-resource-record-sets --hosted-zone-id Z3II3949ZDMDXV --query "ResourceRecordSets[?Name == 'scottstensland.com.']"

... output

[
    {
        "AliasTarget": {
            "HostedZoneId": "Z35SXDOTRQ7X7K",
            "EvaluateTargetHealth": false,
            "DNSName": "dualstack.asomepriorvalue39e7db-1867261689.us-east-1.elb.amazonaws.com."
        },
        "Type": "A",
        "Name": "scottstensland.com."
    },
    {
        "ResourceRecords": [
            {
                "Value": "ns-1238.awsdns-26.org."
            },
            {
                "Value": "ns-201.awsdns-25.com."
            },
            {
                "Value": "ns-969.awsdns-57.net."
            },
            {
                "Value": "ns-1823.awsdns-35.co.uk."
            }
        ],
        "Type": "NS",
        "Name": "scottstensland.com.",
        "TTL": 172800
    },
    {
        "ResourceRecords": [
            {
                "Value": "ns-1238.awsdns-26.org. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400"
            }
        ],
        "Type": "SOA",
        "Name": "scottstensland.com.",
        "TTL": 900
    }
]

... in above notice value of

"HostedZoneId": "Z35SXDOTRQ7X7K",

which is the second similarly name token Do NOT use wrong Hosted Zone ID

step 3 - put below into your change file aws_route53_type_A.json (for syntax Doc see link mentioned in comment above)

{
  "Comment": "Update record to reflect new DNSName of fresh deploy",
  "Changes": [
    {
      "Action": "UPSERT",
      "ResourceRecordSet": {
        "AliasTarget": {
            "HostedZoneId": "Z35SXDOTRQ7X7K",
            "EvaluateTargetHealth": false,
            "DNSName": "dualstack.a0b82c81f47d011e6b98a0a28439e7db-1867261689.us-east-1.elb.amazonaws.com."
        },
        "Type": "A",
        "Name": "scottstensland.com."
      }
    }
  ]
}

To identify value for above field "DNSName" ... after the kubernetes app deploy on aws it responds with a LoadBalancer Ingress as shown in output of cli command :

kubectl describe svc --namespace=ruptureofthemundaneplane

... as in

LoadBalancer Ingress:   a0b82c81f47d011e6b98a0a28439e7db-1867261689.us-east-1.elb.amazonaws.com

... even though my goal is to execute a command line call I can do this manually by getting into the aws console browser ... pull up my domain on route53 ...

... In this browser picklist editable text box (circled in green) I noticed the URL gets magically prepended with : dualstack. Previously I was missing that magic string ... so json key "DNSName" wants this

dualstack.a0b82c81f47d011e6b98a0a28439e7db-1867261689.us-east-1.elb.amazonaws.com.

finally execute the change request

aws route53 change-resource-record-sets --hosted-zone-id Z3II3949ZDMDXV --change-batch file://./aws_route53_type_A.json

... output

{
    "ChangeInfo": {
        "Status": "PENDING",
        "Comment": "Update record to reflect new DNSName of fresh deploy",
        "SubmittedAt": "2016-07-13T14:53:02.789Z",
        "Id": "/change/CFUX5R9XKGE1C"
    }
}

.... now to confirm change is live run this to show record

aws route53  list-resource-record-sets  --hosted-zone-id Z3II3949ZDMDXV

这篇关于如何将kubernetes LoadBalancer入口URL发布到AWS Route53的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 22:21