The question “Kubernetes vs. Docker?” in itself is rather absurd, like comparing apples to oranges. One isn’t an alternative to the other. Quite the contrary, Kubernetes can run without Docker and Docker can function without Kubernetes. But Kubernetes can (and does) benefit greatly from Docker and vice versa.
中文翻译
"“Kubernetes vs. Docker?”这个问题本身相当荒谬,就像比较苹果和橙子一样。它们不是相互替代的。恰恰相反,Kubernetes 可以在没有 Docker 的情况下运行,而 Docker 也可以在没有 Kubernetes 的情况下工作。但 Kubernetes 可以(并且确实)从 Docker 获得很大的好处,反之亦然。"
Docker is a standalone application which can be installed on any computer to run containerized applications. Containerization is an approach of running applications on an OS such that the application is isolated from the rest of the system. You create an illusion for your application that it is getting its very own OS instance, although there may be other containers running on the same system. Docker is what enables us to run, create and manage containers on a single operating system.
中文翻译
Docker 是一个独立的应用程序,可以安装在任何计算机上,用于运行容器化应用程序。容器化是一种在操作系统上运行应用程序的方法,使应用程序与系统的其余部分隔离开来。您为您的应用程序创建了一个假象,让它认为它有自己的操作系统实例,尽管可能在同一系统上运行其他容器。Docker 是让我们能够在单个操作系统上运行、创建和管理容器的工具。
Kubernetes turns it up to eleven. If you have Docker installed on a bunch of hosts (different operating systems), you can leverage Kubernetes. These nodes or Docker hosts can be bare metal servers or virtual machines. Kubernetes can then allow you to automate container provisioning, networking, load-balancing, security and scaling across all these nodes from a single command-line or dashboard. A collection of nodes that are managed by a single Kubernetes instance is referred to as a Kubernetes cluster.
中文翻译
Kubernetes 把它推向了更高级别。如果您在一堆主机上安装了 Docker(不同的操作系统),您可以利用 Kubernetes。这些节点或 Docker 主机可以是裸机服务器或虚拟机。然后,Kubernetes 可以允许您从单个命令行或仪表板自动化容器的配置、网络、负载均衡、安全性和扩展,跨所有这些节点。由单个 Kubernetes 实例管理的一组节点被称为 Kubernetes 集群。
Now, why would you need to have multiple nodes in the first place? The two main motivations behind it are:
中文翻译
那么,为什么首先需要多个节点呢?背后的两个主要动机是
To make the infrastructure more robust — Your application will be online, even if some of the nodes go offline, i.e, High Availability. To make your application more scalable — If workload increases simply spawn more containers and/or add more nodes to your Kubernetes cluster. “Kubernetes automates the process of scaling, managing, updating and removing containers. In other words, it is a container orchestration platform. While Docker is at the heart of the containerization, it enables us to have containers in the first place.
中文翻译
为了使基础设施更加健壮 — 即使一些节点下线,您的应用程序也将在线运行,即实现高可用性。为了使您的应用程序更加可扩展 — 如果工作负载增加,只需生成更多容器和/或添加更多节点到您的 Kubernetes 集群。 "Kubernetes 自动化了扩展、管理、更新和删除容器的过程。换句话说,它是一个容器编排平台。虽然 Docker 是容器化的核心,它使我们能够首次使用容器。
In principle, Kubernetes can work with any containerization technology. Two of the most popular options that Kubernetes can integrate with are rkt and Docker. However, Docker has won the greatest market segment and that has led to a lot of effort in perfecting the integration between Docker and Kubernetes, more than any other containerization technology.
中文翻译
原则上,Kubernetes 可以与任何容器化技术一起使用。Kubernetes 可以与最流行的两种选项集成,分别是 rkt 和 Docker。然而,Docker 赢得了最大的市场份额,这导致了在 Docker 和 Kubernetes 之间完善集成的许多努力,超过了任何其他容器化技术。
Similarly, Docker Inc., the company behind Docker, offers their own container orchestration engine, named Docker Swarm. But even they realized the fact that Kubernetes has risen to the point that even Docker for Desktop (MacOS and Windows) comes with its own Kubernetes distribution.
中文翻译
同样地,Docker Inc.,即 Docker 背后的公司,提供了他们自己的容器编排引擎,名为 Docker Swarm。但即使他们也意识到 Kubernetes 已经崭露头角,以至于即使是 Docker for Desktop(适用于 MacOS 和 Windows)也附带了自己的 Kubernetes 发行版。
If anyone was nervous about adopting Kubernetes for their Docker-based product, that last point would get rid of all of the doubts. Both projects have wholeheartedly embraced each other and have benefited tremendously from this symbiosis.
中文翻译
如果有人对于在其基于 Docker 的产品中采用 Kubernetes 感到紧张,那么最后一点将消除所有疑虑。这两个项目都全力拥抱了彼此,并从这种共生关系中获得了巨大的好处。
These projects are more than technologies, they are a community of people, who, despite their differences, are is composed of some of the brightest minds in the industry. When like-minded individuals collaborate, they exchange bright ideas and learn best practices from one another.
These are some of such ideas that both, Kubernetes and Docker, share:
中文翻译
这些项目不仅仅是技术,它们是一群人的社区,尽管他们之间存在差异,但组成这些社区的人才是该行业中最杰出的一些人。当志同道合的个体合作时,他们交流睿智的思想,并从彼此那里学习最佳实践。
以下是该段话中的关键单词的中文意思:
Their love for microservice based architecture (more on this later). Their love for open source community. Both are largely open source projects. They are largely written in Go which allows them to be shipped as small lightweight binaries. They use human-readable YAML files to specify application stacks and their deployments. In theory, you can learn about one without having a clue about the other. But keep in mind that in practice you will benefit a lot more if you start with the simple case of Docker running on a single machine, and then gradually understand how Kubernetes comes into play.
中文翻译
他们对微服务架构的热爱(稍后会详细介绍)。 他们对开源社区的热爱。它们都是大规模的开源项目。 它们主要是用 Go 语言编写的,这使它们能够作为小型轻量级二进制文件进行发布。 它们使用人类可读的 YAML 文件来指定应用程序堆栈及其部署。 从理论上讲,您可以了解其中一个而对另一个一无所知。但请记住,在实践中,如果您从单台机器上运行 Docker 的简单情况开始,然后逐渐了解 Kubernetes 如何运作,您将受益良多。
Containers are amazing! They allow us to think about services and systems in a completely new and digital way. Both Docker and Kubernetes are here to stay. They are continuously changing to transform themselves into something better in the future. Keep your company involved in the Technology era and implement the containers that your infrastructure needs the most.
中文翻译
容器是令人惊奇的!它们使我们能够以全新的数字方式思考服务和系统。Docker 和 Kubernetes 都将继续存在。它们正在不断变化,以将自己转变为未来更好的东西。让您的公司参与科技时代,并实施您的基础设施最需要的容器。
Designing newer software for a container-centric platform would not only make your apps more scalable but also more future-proof. Sticking to the old VMs might work for now, but a few years down the line you will eventually have to either bear the heavy cost of migrating everything into containers or abandon your projects altogether. Hopefully, now if someone brings up the topic of “Kubernetes vs Docker” you won’t get swept away by jargons.
中文翻译
为容器为中心的平台设计新的软件不仅会使您的应用程序更具可扩展性,而且更具未来可塑性。坚持使用旧的虚拟机可能暂时有效,但几年后,您最终将不得不承担将所有内容迁移到容器中的巨大成本,或者完全放弃您的项目。希望现在如果有人提出“Kubernetes vs Docker”的话题,您不会被术语所迷惑。
Is going to college for computer science with a focus of software engineering still worth it in 2023? I just finished my freshman year of college.
中文翻译
在2023年,选择攻读计算机科学专业,专注于软件工程方向,是否仍然值得?我刚刚完成大学一年级。
You have three choices:
1.Continue in computer science.
2.Change to a different major.
3.Drop out of college.
Each of these carries risk and potential rewards. If you're only pursuing CS because you dream of making $150k
right after graduating college, I think you should choose something else. The market has shifted and that was not a sustainable reality. I warned that it would come to an end. There will be great opportunities, but making $300k 3–4 years out of college will be reserved for exceptional talent.
But if you stay, you will get a solid education that balances theory and practice. I don't know what the job market will look like in two years when you start applying for post-grad jobs, but there will be computing jobs.
中文翻译
你有三个选择:
每个选择都有风险和潜在回报。如果你只是追求计算机科学专业,因为你梦想着在大学毕业后能够赚取15万美元,我认为你应该选择其他专业。市场已经发生了变化,那并不是一个可持续的现实。我曾警告过这种情况会结束。将来会有很好的机会,但赚取30万美元的机会将仅限于非凡的人才。
但是,如果你选择留下来,你将得到一种理论与实践相结合的扎实教育。我不知道两年后你开始申请毕业后的工作时,就业市场会是什么样子,但计算机相关的工作机会将会存在。
As a computer science educator if you can teach only one thing to your students what would it be?
中文翻译
作为一名计算机科学教育者,如果你只能教授一件事给你的学生,那会是什么?
Algorithmic thinking. There's a lot that underlies that, but you fundamentally need to be able to learn how to break problems down in to smaller solvable tasks, and apply tightly constrained instructions to solve those tasks. The rest is just syntactic sugar and math. Really, really important math.
中文翻译
Algorithmic thinking(算法思维)是一种重要的思维方式,它需要学会将问题分解为可解决的小任务,并应用严格限定的指令来解决这些任务。除此之外,算法思维还涉及到一些基础的数学知识。算法思维是计算机科学中的核心概念,它帮助我们设计和实现高效的解决方案。除了语法和数学知识外,算法思维是非常重要的。
I want to teach my students how to fail. Part of learning to fail is simple programming practice. It's fundiversión to write code, and the temptation is to write dozens of lines of code at a time. It's much less fun to debug code, and when your dozens of lines fails in strange ways you've made your life far more difficult than it needs to be. So take baby steps: write the smallest number of lines that can be tested, then stop and test it. That code will fail, too, but debugging it will be a relatively pain-free process and you get the psychological boost of solving lots of small failures relatively quickly.
中文翻译
"我想教我的学生如何失败。学习失败的一部分是简单的编程实践。编写代码很有趣,很容易一次写下几十行代码。但调试代码就没那么有趣了,当你的几十行代码以奇怪的方式失败时,你让自己的生活变得比必要的困难得多。所以要采取小步骤:写下最少的可以测试的代码行,然后停下来进行测试。那段代码也会失败,但调试起来相对轻松,而且你会获得在相对短的时间内成功解决许多小失败的心理推动。"
Source control also has a role to play here. If you commit often, you can occasionally take larger risks secure in knowing that if it doesn't work out, one command will bring you back to a known state.
中文翻译
"版本控制在这方面也起着重要作用。如果经常提交代码,你可以偶尔冒一些较大的风险,因为你知道如果不成功,只需一个命令就能将代码还原到已知状态。"
The deeper lesson is divorcing code that fails from the feeling of failure. If your code X produced state Y and you wanted state Z, and you take this personally, you're in for a long semester. If, on the other hand, I can convince you that you've now learned something you didn't know before about code X, then you're much less likely to feel helpless. If you're not feeling helpless, it's a lot easier to try something different and eventually (after visiting states P, D, Q, and aleph-1) getting to Z.
中文翻译
"更深层次的教训是将失败的代码与失败的感觉分离开来。如果你的代码 X 产生了状态 Y,而你想要的是状态 Z,如果你将此视为个人失败,那么你将度过漫长的学期。另一方面,如果我能够说服你,让你相信你现在学到了关于代码 X 的一些以前不知道的东西,那么你就不太可能感到无助。如果你不感到无助,尝试不同的方法就会容易得多,最终(在经历了状态 P、D、Q 和 aleph-1 之后)达到状态 Z。"
Once you've learned how to do controlled failures and divorce programming failure from the emotion of failure, programming starts to become pretty enjoyable and your learning rate goes up by an order of magnitude.
中文翻译
"一旦你学会了如何进行可控的失败,并将编程失败与情绪分离开来,编程就会变得非常有乐趣,你的学习速度将提高一个数量级。"
以下是可能导致POST请求发送两次的一些原因:
重复提交:用户可能在提交表单或发送POST请求时多次点击提交按钮或发送请求的操作,导致请求被发送多次。
页面刷新:当用户在提交POST请求后刷新页面时,某些浏览器会尝试重新发送之前的POST请求,以便用户可以重新加载页面并继续之前的操作。
跨域请求:在某些情况下,如果你的网页中存在跨域请求,浏览器可能会发送OPTIONS请求进行预检(preflight),然后再发送实际的POST请求。这样就会导致看起来像是发送了两次POST请求,但实际上第一个请求是OPTIONS请求。
重定向:如果服务器返回一个重定向响应(例如状态码为302),浏览器可能会自动跟随重定向并发送第二个POST请求。
缓存问题:一些缓存机制可能会导致POST请求被重复发送。例如,浏览器或代理服务器可能会缓存POST请求的响应,然后在后续请求时重用缓存的响应,从而导致看起来像是发送了两次POST请求。
以下是一些常见的解决方法:
根据具体的情况,你可能需要进一步调查并采取适当的解决措施来处理重复发送的POST请求。
同源策略(Same-Origin Policy)是一种浏览器安全机制,用于限制在浏览器中加载的网页脚本与来自不同源(即不同的域、协议或端口)的资源之间的交互操作。它是为了保护用户的隐私和安全而设计的。
同源策略的基本原则是,当一个网页脚本尝试访问另一个源的资源时,浏览器会阻止这种跨源的操作,以防止恶意网站利用跨域请求获取用户的敏感信息或对其他网站进行攻击。
同源策略的限制主要包括以下几个方面:
域名:同源策略要求两个网页具有相同的域名(协议、主机和端口),即使两个域名只是在协议、主机或端口上稍有不同,也会被视为不同源。例如,http://example.com 和 https://example.com 被视为不同源。
Cookie、LocalStorage 和 IndexDB:同源策略限制了对跨源的 Cookie、LocalStorage 和 IndexDB 的访问。这意味着网页脚本只能访问属于同一源的 Cookie 和存储数据,而无法读取或修改其他源的数据。
DOM 访问:同源策略限制了对跨源文档对象模型(DOM)的访问。网页脚本只能修改属于同一源的 DOM 元素,无法直接访问或修改其他源的 DOM。
XMLHttpRequest 和 Fetch 请求:同源策略对跨源的 XMLHttpRequest 和 Fetch 请求进行限制。通常情况下,这些请求只能向同源发起,无法直接访问其他源的数据。
为了允许跨域请求,浏览器引入了一些机制,如跨域资源共享(CORS)和服务器代理。这些机制允许服务器通过设置适当的响应头来授权特定的跨域请求。
同源策略在保护用户隐私和安全方面起着重要的作用,防止恶意网站滥用用户的信息。然而,有时候需要进行跨域操作,因此开发人员需要了解和遵守跨域规则,并使用适当的跨域解决方案。
预请求(Preflight Request)是在进行跨域资源共享(CORS)时,某些特定情况下由浏览器自动发送的一种HTTP请求。它是一个OPTIONS请求,用于在实际的跨域请求之前进行预检,以确定是否允许实际请求的发送。
在以下情况下,浏览器会发送预请求:
跨域请求:当浏览器发起跨域请求时,即请求的目标与当前页面的域名、协议或端口不一致时,浏览器会发送预请求。
自定义请求头:如果在跨域请求中使用了特定的自定义请求头(例如Content-Type、Authorization等),并且这些请求头属于 "CORS安全列表" 之外的请求头,浏览器也会发送预请求。
预请求的目的是为了确保服务器支持跨域请求并允许浏览器发送实际的跨域请求。预请求的发送和处理过程如下:
发送预请求:浏览器在发送实际的跨域请求之前,先发送一个OPTIONS请求,其中包含了一些额外的头部信息,如Origin(指示请求的源)和Access-Control-Request-Method(指示实际请求的方法)等。
服务器处理预请求:服务器接收到预请求后,进行预检查。它会检查请求的源是否在允许的跨域列表中,以及是否允许实际请求的方法、请求头等。
响应预请求:服务器根据预检查的结果,返回包含了对应的响应头信息的响应。响应头中重要的字段是Access-Control-Allow-Origin(指示允许的源)和Access-Control-Allow-Methods(指示允许的方法)等。
浏览器处理预请求响应:浏览器接收到预请求的响应后,会检查响应头中的相关字段,以确定是否允许发送实际的跨域请求。
发送实际请求:如果预请求的响应表明服务器允许实际请求,浏览器会发送实际的跨域请求,其中包含了实际的请求方法、请求头等。
需要注意的是,预请求是由浏览器自动发送的,并且在实际请求之前进行。它的目的是为了提供一种机制,确保服务器允许跨域请求,以增加安全性。服务器需要正确地处理预请求并返回适当的响应头,以允许或拒绝实际的跨域请求。
预请求就是浏览器在进行跨域请求访问时向目标浏览器发送的一个预检测请求,检测目标服务器是否支持跨域请求,预请求是一个OPTIONS请求,其中包含了一些额外的头部信息,如Origin(请求源)、Access-Control-Request-Method(实际请求的方法)和Access-Control-Request-Headers(实际请求的头部信息)。服务器收到预请求后,可以检查这些头部信息,并决定是否允许实际的跨域请求。
服务器在收到预请求后,可以通过设置响应头部中的Access-Control-Allow-Origin、Access-Control-Allow-Methods和Access-Control-Allow-Headers等字段来指定允许的跨域请求来源、方法和头部信息。如果服务器确认允许跨域请求,浏览器会继续发送实际的跨域请求,否则将阻止实际请求的发送,并返回相应的错误。
预请求机制的目的是确保服务器允许跨域请求,并在发送实际请求之前进行验证,从而保护用户的隐私和安全。开发人员需要在服务器上正确地配置CORS头部信息,以便处理预请求,并允许必要的跨域请求。
1.通过自定义中间件
package main import ( "github.com/gin-gonic/gin" ) func main() { // 创建 Gin 引擎 router := gin.Default() // 添加跨域请求的中间件 router.Use(corsMiddleware()) // 添加你的路由处理逻辑 // 启动服务器 router.Run(":8080") } // 跨域请求中间件 func corsMiddleware() gin.HandlerFunc { return func(c *gin.Context) { // 设置允许的请求来源 c.Writer.Header().Set("Access-Control-Allow-Origin", "http://example.com") // 设置允许的请求方法 c.Writer.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE") // 设置允许的请求头部信息 c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization") // 设置是否允许发送凭据 c.Writer.Header().Set("Access-Control-Allow-Credentials", "true") // 如果是预请求(OPTIONS请求),则直接返回 if c.Request.Method == "OPTIONS" { c.AbortWithStatus(204) return } // 继续处理实际的请求 c.Next() } }
2.官方推荐跨域请求中间件,具体可以看官方示例代码