当前位置: 首页 > 编程日记 > 正文

ecs和eks 比较_如何使用Kubernetes,EKS和NGINX为网站设置DNS

ecs和eks 比较

As the creator of Foo, a platform for website quality monitoring, I recently endeavored in a migration to Kubernetes and EKS (an AWS service).

作为网站质量监控平台Foo的创建者,我最近努力迁移到Kubernetes和EKS(一种AWS服务)。

Kubernetes provides a robust level of DNS support. Luckily for us, within a cluster, we can reference pods by host name as defined in a spec.

Kubernetes提供了强大的DNS支持级别。 对我们来说幸运的是,在集群中,我们可以按规范中定义的主机名引用Pod。

But what if we want to expose an app to the outside world as a website under a static domain? I thought this would be a common, well documented case, but boy was I wrong.

但是,如果我们想将应用程序作为静态站点下的网站公开给外界,该怎么办? 我以为这是一个常见且有据可查的案例,但是男孩我错了。

Assume a Service named foo in the Kubernetes namespace bar. A Pod running in namespace bar can look up this service by simply doing a DNS query for foo. A Pod running in namespace quux can look up this service by doing a DNS query for foo.bar ~ DNS for Services and Pods - Kubernetes

在Kubernetes命名空间bar假设一个名为foo的服务。 在名称空间bar运行的Pod可以通过对foo进行DNS查询来查找此服务。 在命名空间quux运行的Pod可以通过对foo.bar进行DNS查询来查找此服务〜 服务和 foo.bar DNS-Kubernetes

Yes, that's great ❤️ But this still leads to many unsolved mysteries. Let's take this one step at a time shall we?! This post will address the following items.

是的,太好了❤️但这仍然导致许多未解之谜。 让我们一次迈出这一步吧? 这篇文章将解决以下问题。

  1. How to define services

    如何定义服务

  2. How to expose multiple services under one NGINX server. No fancy schmancy "Ingress" needed 🙌

    如何在一台NGINX服务器下公开多种服务 。 无需花哨的“ Ingress ” 🙌

  3. How to create an external DNS and connect to a domain you've acquired through any qualified registry like GoDaddy or Google Domains, for example. We'll use Route 53 and ExternalDNS to do the heavy lifting.

    例如,如何创建外部DNS并连接到通过任何合格的注册表(例如GoDaddy或Google Domains)获得的域。 我们将使用Route 53和ExternalDNS进行繁重的工作。

This post assumes a setup with EKS and eksctl as documented in "Getting started with eksctl", but many of the concepts and examples in this post could be applicable in a variety of configurations.

这篇文章假定使用“ eksctl入门 ”中介绍的EKS和eksctl进行设置,但是本文中的许多概念和示例可能适用于各种配置。

步骤1:定义服务 (Step 1: Define Services)

Connecting Applications with Services explains how to expose an NGINX application by defining a Deployment and Service. Let's go ahead and create 3 applications in the same manner: a user facing web app, an API and a reverse proxy NGINX server to expose the two apps under one host.

将应用程序与服务连接说明了如何通过定义DeploymentService来公开NGINX应用程序。 让我们以相同的方式继续创建3个应用程序:一个面向用户的Web应用程序,一个API和一个反向代理NGINX服务器,以将两个应用程序公开在一个主机下。

web-deployment.yaml
web-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:name: web
spec:selector:matchLabels:app: webtemplate:metadata:labels:app: webspec:containers:- name: web# etc, etc
web-service.yaml
web-service.yaml
apiVersion: v1
kind: Service
metadata:name: weblabels:app: web
spec:ports:- name: "3000"port: 3000targetPort: 3000selector:app: web
api-deployment.yaml
api-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:name: api
spec:replicas: 1selector:matchLabels:app: apitemplate:metadata:labels:app: apispec:containers:- name: api# etc, etc
api-service.yaml
api-service.yaml
apiVersion: v1
kind: Service
metadata:name: apilabels:app: api
spec:ports:- name: "3000"port: 3000targetPort: 3000selector:app: api

Fair enough, let's move on!

公平地说,让我们继续前进!

步骤2:在一台NGINX服务器下公开多种服务 (Step 2: Expose Multiple Services Under One NGINX Server)

NGINX is a reverse proxy in that it proxies a request by sending it to a specified origin, fetches the response, and sends it back to the client.

NGINX是反向代理,它通过将请求发送到指定的来源来代理请求,获取响应,然后将其发送回客户端。

Going back to the bit about service names being accessible to other pods in a cluster, we can setup an NGINX configuration to look something like this.

回到关于服务名称可以被集群中其他Pod访问的地方,我们可以设置NGINX配置看起来像这样。

sites-enabled/www.example.com.conf
网站启用/www.example.com.conf
upstream api {server api:3000;
}upstream web {server web:3000;
}server {listen 80;server_name www.example.com;location / {proxy_pass http://web;}location /api {proxy_pass http://api;}
}

Note how we can reference origin hosts like web:3000 and api:300. Niiiice!

注意我们如何引用原始主机,例如web:3000api:300 。 Niiii​​ce!

nginx-deployment.yaml
nginx-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:name: nginx
spec:selector:matchLabels:app: nginxtemplate:metadata:labels:app: nginxspec:containers:- name: nginximage: nginxports:- containerPort: 80
nginx-service.yaml
nginx-service.yaml
apiVersion: v1
kind: Service
metadata:name: nginxannotations:# this part will make more sense laterexternal-dns.alpha.kubernetes.io/hostname: www.example.comlabels:app: nginx
spec:type: LoadBalancerports:- name: "80"port: 80targetPort: 80selector:app: nginx

...and, we're done! Right? In my experience, initially I thought so. The LoadBalancer provides an externally-accessible IP. You can confirm by running kubectl get svc and sure enough you'll find a host name listed in the EXTERNAL-IP column.

...而且,我们完成了! 对? 根据我的经验,最初我是这么认为的。 LoadBalancer提供了一个外部可访问的IP。 您可以通过运行kubectl get svc进行确认,并确保您会在EXTERNAL-IP列中找到列出的主机名。

Assuming you've acquired a domain from a provider that offers an interface to manage DNS settings, you could simply add this URL as a CNAME and you're good, right? Well, kinda... but not so much.

假设您已从提供接口的提供商处获取了一个域来管理DNS设置,则只需将此URL添加为CNAME就可以了,对吗? 好吧...不过不是很多。

Kubernetes Pods are considered to be relatively ephemeral (rather than durable) entities. Find more on this in "Pod Lifecycle - Kubernetes".

Kubernetes Pod被认为是相对短暂的(而不是持久的)实体。 在“ Pod生命周期-Kubernetes ”中找到更多相关信息。

With that said, anytime a significant change has been made in the lifecycle of a service, in our case the NGINX app, we will have a different IP address which will in turn cause significant downtime in our app which defeats a main purpose of Kubernetes - to help establish a "highly available" application.

话虽如此,每当服务的生命周期发生重大变化时(在我们的示例中为NGINX应用程序),我们将拥有一个不同的IP地址,这将导致我们的应用程序出现大量停机,从而无法达到Kubernetes的主要目的-帮助建立“高度可用”的应用程序。

Okay, don't panic - we'll get through this 😬

好吧,不要惊慌-我们会解决这个问题

步骤3:创建外部DNS服务以动态指向NGINX (Step 3: Create an External DNS Service to Dynamically Point NGINX)

In the previous step, with our LoadBalancer spec coupled with EKS we actually created an Elastic Load Balancer (for better or worse).

在上一步中,结合我们的LoadBalancer规范和EKS,我们实际上创建了一个Elastic Load Balancer (无论好坏)。

In this section we'll create a DNS service that points our load balancer via "ALIAS record". This ALIAS record is essentially dynamic in that a new one is created whenever our service changes. The stability is established in the name server records.

在本部分中,我们将创建一个DNS服务,该服务通过“ ALIAS记录”指向负载均衡器。 该ALIAS记录本质上是动态的,因为只要我们的服务发生更改,就会创建一个新记录。 稳定性在名称服务器记录中建立。

The tl;dr for the remaining portion is simply follow the documentation for using ExternalDNS with Route 53. Route 53 is "cloud Domain Name System (DNS) web service".

其余部分的tl; dr仅需遵循将外部DNS与Route 53结合使用的文档即可。 路线53是“ 云域名系统(DNS)Web服务 ”。

Below were things I had to do that weren't obvious from the documentation. Hold on to your horses, this gets a little scrappy.

以下是我必须执行的操作,这些操作在文档中并不明显。 抓紧你的马,这会变得有点杂乱。

  • eksctl utils associate-iam-oidc-provider --cluster=your-cluster-name per eksctl service accounts documentation.

    eksctl utils associate-iam-oidc-provider --cluster=your-cluster-name每个eksctl服务帐户文档) 。

  • When creating the IAM policy document per the ExternalDNS documentation, I actually had to do it via CLI vs online in my account. I kept getting this error: WebIdentityErr: failed to retrieve credentials\ncaused by: AccessDenied: Not authorized to perform sts:AssumeRoleWithWebIdentity\n\tstatus code: 403. When I created the policy via CLI the issue went away. Below is the full command you should be able to literally copy and execute if you have the AWS CLI installed.

    根据ExternalDNS文档创建IAM策略文档时,实际上我必须通过CLI而不是通过帐户在线进行。 我一直收到此错误: WebIdentityErr: failed to retrieve credentials\ncaused by: AccessDenied: Not authorized to perform sts:AssumeRoleWithWebIdentity\n\tstatus code: 403 。 当我通过CLI创建策略时,问题就消失了。 如果您已安装AWS CLI,则以下是您应该能够完整复制并执行的完整命令。

aws iam create-policy \--policy-name AllowExternalDNSUpdates \--policy-document '{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":["route53:ChangeResourceRecordSets"],"Resource":["arn:aws:route53:::hostedzone/*"]},{"Effect":"Allow","Action":["route53:ListHostedZones","route53:ListResourceRecordSets"],"Resource":["*"]}]}'
  • Use the policy ARN output above to create an IAM role bound to the ExternalDNS service account with a command that will look something like eksctl create iamserviceaccount --cluster=your-cluster-name --name=external-dns --namespace=default --attach-policy-arn=arn:aws:iam::123456789:policy/AllowExternalDNSUpdates.

    使用上面的策略ARN输出,使用类似于eksctl create iamserviceaccount --cluster=your-cluster-name --name=external-dns --namespace=default --attach-policy-arn=arn:aws:iam::123456789:policy/AllowExternalDNSUpdates的命令,创建绑定到ExternalDNS服务帐户的IAM角色eksctl create iamserviceaccount --cluster=your-cluster-name --name=external-dns --namespace=default --attach-policy-arn=arn:aws:iam::123456789:policy/AllowExternalDNSUpdates

  • We should now have a new role from the above that we can see in the IAM console which will have a name of something like eksctl-foo-addon-iamserviceaccount-Role1-abcdefg. Click on the role from the list and at the top of the next screen make note of the "Role ARN" as something like arn:aws:iam::123456789:role/eksctl-foo-addon-iamserviceaccount-Role1-abcdefg.

    现在,我们应该在IAM控制台中看到一个以上的新角色,其名称类似于eksctl-foo-addon-iamserviceaccount-Role1-abcdefg 。 单击列表中的角色,然后在下一个屏幕顶部记录“角色ARN”,如arn:aws:iam::123456789:role/eksctl-foo-addon-iamserviceaccount-Role1-abcdefg

  • Follow these steps to create a "hosted zone" in Route 53.

    请按照以下步骤在Route 53中创建“托管区域”。

  • You can confirm things in the Route 53 console.

    您可以在Route 53控制台中确认情况。

  • If your domain provider allows you to manage DNS settings, add the 4 name server records from the output of the command you ran to create a "hosted zone".

    如果您的域提供商允许您管理DNS设置,请从运行“创建托管区域”的命令的输出中添加4个名称服务器记录。
  • Deploy ExternalDNS by following the instructions. Afterwards, you can tail the logs with kubectl logs -f name-of-external-dns-pod. You should see a line like this at the end: time="2020-05-05T02:57:31Z" level=info msg="All records are already up to date"

    按照说明部署ExternalDNS。 之后,您可以使用kubectl logs -f name-of-external-dns-pod 。 您应该在末尾看到这样的一行: time="2020-05-05T02:57:31Z" level=info msg="All records are already up to date"

Easy, right?! Okay, maybe not... but at least you didn't have to figure all of that out alone 😓 There could be some gaps above, but hopefully it helps guide you through your process.

容易吧? 好的,也许不是……但是至少您不必独自解决所有问题above上面可能存在一些差距,但是希望它可以指导您完成整个过程。

结论 (Conclusion)

Although this post may have some grey areas, if it helps you establish dynamic DNS resolution as part of a highly available application, you've got something really special 🙏

尽管这篇文章可能有一些灰色区域,但是如果它可以帮助您建立动态DNS解析作为高可用性应用程序的一部分,那么您会发现一些特别的东西🙏

Please add comments if I can help clear up anything or correct my terminology!

如果我可以帮助您清除任何内容或更正我的术语,请添加评论!

翻译自: https://www.freecodecamp.org/news/how-to-setup-dns-for-a-website-using-kubernetes-eks-and-nginx/

ecs和eks 比较

相关文章:

仅需6步,教你轻易撕掉app开发框架的神秘面纱(1):确定框架方案

遇到的问题 做游戏的时候用的是cocos2dxlua,游戏开发自有它的一套框架机制。而现在公司主要项目要做android和iOS应用。本文主要介绍如何搭建简单易用的App框架。 如何解决 对于新手来说,接触一门新的知识,往往会思考该怎么入手,…

js全局变量污染

一.定义全局变量命名空间 只创建一个全局变量,并定义该变量为当前应用容器,把其他全局变量追加在该命名空间下 var my{}; my.name{big_name:"zhangsan",small_name:"lisi" }; my.work{school_work:"study",family_work:&q…

cached-query 将缓存和查询数据库高速连接起来的轻类库

介绍 我们经常有这种需求:当我们把memcached增加到项目后我还还要写一个 cacheUtils 或者 cacheManager 之类的类来操作memcached。而且一般的操作不外乎是这种操作: 拿到一段sql,先去memcahed里面看下是否有缓存,假设有就直接返回…

全栈Python Flask教程-建立社交网络

Learn how to build a basic social platform with the Python Flask web framework. 了解如何使用Python Flask网络框架构建基本的社交平台。 In this video, we show you how to:在此视频中,我们向您展示如何: how to create a database, 如何创建数…

py执行系统命令

py执行系统命令 1. os.system In [32]: run os.system("date") Thu Jan 28 09:41:25 CST 2016 In [33]: run Out[33]: 0 只能得到返回值&#xff0c;无法得到输出。 2. os.popen In [35]: run os.popen("date") In [36]: run.read Out[36]: <function…

仅需6步,教你轻易撕掉app开发框架的神秘面纱(2):MVP比MVC更好吗

对于程序框架的选择&#xff0c;由于android天然的MVC&#xff0c;本来不需要另外设计直接使用即可。但是我更加钟情于MVP模式&#xff0c;对于其将ui完全与业务逻辑分离的思路很赞同。 那么什么是业务逻辑&#xff1f;个人认为&#xff0c;对数据&#xff08;即MVC中的M&…

一、nginx 安装

添加官方 yum 源 1 vim /etc/yum.repos.d/nginx.rep 输入以下内容&#xff08;OS为你的系统&#xff0c;OSRELEASE 系统版本&#xff09; 1 [nginx] 2 namenginx repo 3 baseurlhttp://nginx.org/packages/mainline/OS/OSRELEASE/$basearch/ 4 gpgcheck0 5 enabled1 列出可安装…

华为技术面试编码题_最佳技术编码面试准备书

华为技术面试编码题Technical coding interviews are notoriously difficult — almost borderline quiz-like for those unprepared. It can sometimes be a daunting task to navigate all the technical coding preparation resources available online, and one might as…

仅需6步,教你轻易撕掉app开发框架的神秘面纱(3):构造具有个人特色的MVP模式

1. MVP的问题 之前我们说过MVP模式最大的问题在于&#xff1a;每写一个Activity/Fragment需要写4个对应的文件&#xff0c;对于一个简易的app框架来说太麻烦了。所以我们需要对MVP进行一定的简化。 关于MVP模式是什么及其简单实现&#xff0c;可以参照&#xff1a;浅谈 MVP i…

Java进阶之自动拆箱与自动装箱

序. java基本类型介绍 java中&#xff0c;基本数据类型一共有8种&#xff0c;详细信息如下表&#xff1a; 类型大小范围默认值byte8-128 - 1270short16-32768 - 327680int32-2147483648-21474836480long64-9233372036854477808-92333720368544778080float32-3.40292347E38-3.40…

Ceilometer Polling Performance Improvement

Ceilometer的数据采集agent会定期对nova/keystone/neutron/cinder等服务调用其API的获取信息&#xff0c;默认是20秒一次&#xff0c; # Polling interval for pipeline file configuration in seconds.# (integer value)#pipeline_polling_interval 20 这在大规模部署中会对O…

vue使用pwa_如何使用HTML,CSS和JavaScript从头开始构建PWA

vue使用pwaProgressive web apps are a way to bring that native app feeling to a traditional web app. With PWAs we can enhance our website with mobile app features which increase usability and offer a great user experience.渐进式Web应用程序是一种将本地应用程…

仅需6步,教你轻易撕掉app开发框架的神秘面纱(4):网络模块的封装

程序框架确定了&#xff0c;还需要封装网络模块。 一个丰富多彩的APP少不了网络资源的支持&#xff0c;毕竟用户数据要存储&#xff0c;用户之间也要交互&#xff0c;用户行为要统计等等。 使用开源框架 俗话说得好&#xff0c;轮子多了路好走&#xff0c;我们不需要自己造轮…

结构体成员数组不定长如何实现

【目的】 定义一个结构体类&#xff0c;其中的成员变量数组长度不定&#xff0c;根据实例化的对象指定长度&#xff0c;所以想到用指针实现 【现状】 指针可以指向任意长度数组&#xff0c;但结构体类只分配指针本身4字节长度&#xff0c;所以无法扩展 1 /**2 ****************…

团队项目:二次开发

至此&#xff0c;我们有了初步的与人合作经验&#xff0c;接下来投入到更大的团队中去。 也具备了一定的个人能力&#xff0c;能将自己的代码进行测试。接下来尝试在别人已有的基础上进行开发。 上一界51冯美欣同学的项目&#xff1a;http://www.cnblogs.com/maxx/ 1.每个团队从…

arduino 呼吸灯_如何改善您的Arduino呼吸机:用于临时COVID-19呼吸机设计的RTS和SCS简介...

arduino 呼吸灯The world as we know it was recently taken by storm. That storm was the outbreak of the COVID-19 pandemic. This has in turn created a shortage of ventilators world wide which has led many people to foray into the world of ventilator design. 我…

reboot 百度网盘资源

提醒&#xff1a;同志们这是记录&#xff0c;视频文件是加密的&#xff0c;请勿下载 基础班第十三期&#xff1a;http://pan.baidu.com/s/1c2GcvKG 密码: 743j 基础班第十四期链接: http://pan.baidu.com/s/1c24AYa8 密码: x2sh 第十五期&#xff1a; https://pan.baidu.com…

仅需6步,教你轻易撕掉app开发框架的神秘面纱(5):数据持久化

遇到的问题 有的时候程序中需要全局皆可访问的变量&#xff0c;比如&#xff1a;用户是否登录&#xff0c;用户个人信息(用户名&#xff0c;地区&#xff0c;生日)&#xff0c;或者一些其他信息如&#xff1a;是否是首次登录&#xff0c;是否需要显示新手引导等等。 其中有些…

响应因特网端口ping命令_如何使用Ping命令识别基本的Internet问题

响应因特网端口ping命令Next time you call your help desk, do you want to wow them with your networking knowledge? Using a command called “ping”, built right into your existing Mac, Windows, or Linux computer, will help identify basic connection problems.…

Android 常见工具类封装

1&#xff0c;MD5工具类&#xff1a; public class MD5Util {public final static String MD5(String s) {char hexDigits[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,a, b, c, d, e, f };try {byte[] btInput s.getBytes();// 获得MD5摘要算法的 MessageDigest 对象MessageDigest md…

keras系列︱图像多分类训练与利用bottleneck features进行微调(三)

引自&#xff1a;http://blog.csdn.net/sinat_26917383/article/details/72861152 中文文档&#xff1a;http://keras-cn.readthedocs.io/en/latest/ 官方文档&#xff1a;https://keras.io/ 文档主要是以keras2.0。 训练、训练主要就”练“嘛&#xff0c;所以堆几个案例就知…

LIKE 操作符

LIKE 操作符LIKE 操作符用于在 WHERE 子句中搜索列中的指定模式。SQL LIKE 操作符语法SELECT column_name(s)FROM table_nameWHERE column_name LIKE pattern原始的表 (用在例子中的)&#xff1a;Persons 表:IdLastNameFirstNameAddressCity1AdamsJohnOxford StreetLondon2Bush…

服务器云ide_语言服务器协议如何影响IDE的未来

服务器云ideThe release of Visual Studio Code single-handedly impacted the developer ecosystem in such a way that theres no going back now. Its open source, free, and most importantly, a super powerful tool. Visual Studio Code的发布以一种无可匹敌的方式对开发…

仅需6步,教你轻易撕掉app开发框架的神秘面纱(6):各种公共方法及工具类的封装

为什么要封装公共方法 封装公共方法有2方面的原因&#xff1a; 一是功能方面的原因&#xff1a;有些方法很多地方都会用&#xff0c;而且它输入输出明确&#xff0c;并且跟业务逻辑无关。比如检查用户是否登录&#xff0c;检查某串数字是否为合法的手机号。像这种方法就应该封…

MySQL优化配置之query_cache_size

原理MySQL查询缓存保存查询返回的完整结果。当查询命中该缓存&#xff0c;会立刻返回结果&#xff0c;跳过了解析&#xff0c;优化和执行阶段。 查询缓存会跟踪查询中涉及的每个表&#xff0c;如果这写表发生变化&#xff0c;那么和这个表相关的所有缓存都将失效。 但是随着服…

request.getSession()

request.getSession(); 与request.getSession(false);区别 服务器把session信息发送给浏览器 浏览器会将session信息存入本地cookie中 服务器本地内存中也会留一个此session信息 以后用户发送请求时 浏览器都会把session信息发送给服务器 服务器会依照浏览器发送过来的se…

alpine 交互sh_在这个免费的交互式教程中学习Alpine JS

alpine 交互shAlpine.js is a rugged, minimal framework for composing Javascript behavior in your markup. Thats right, in your markup! Alpine.js是一个坚固的最小框架&#xff0c;用于在标记中构成Javascript行为。 是的&#xff0c;在您的标记中&#xff01; It allo…

浅谈 MVP in Android

一、概述 对于MVP&#xff08;Model View Presenter&#xff09;&#xff0c;大多数人都能说出一二&#xff1a;“MVC的演化版本”&#xff0c;“让Model和View完全解耦”等等。本篇博文仅是为了做下记录&#xff0c;提出一些自己的看法&#xff0c;和帮助大家如何针对一个Acti…

test markdown

test test public void main(String[] args){System.out.println("test"); } 转载于:https://www.cnblogs.com/cozybz/p/5427053.html

java开发工具对比eclipse·myeclipse·idea

eclipse:不说了&#xff0c;习惯了 myeclipse&#xff1a;MyEclipse更适合企业开发者&#xff0c;更团队开发 idea:idea更适合个人开发者,细节优化更好转载于:https://www.cnblogs.com/gjack/p/8136964.html