简体   繁体   English

Kubernetes Pods与Google Cloud中的部署

[英]Kubernetes Pods vs Deployments in Google Cloud

My apologies if this question sounds obvious, but the Kubernetes and Google cloud documentation is extremely confusing and contradictory in places. 如果这个问题听起来很明显,我很抱歉,但Kubernetes和Google云文档在某些地方非常混乱和矛盾。

Anyway, I have pushed a Dockerized web-server to my private Google Container Registry. 无论如何,我已经将Dockerized网络服务器推送到我的私人Google Container Registry。 I want this container to be restarted if it dies, but I only need one single instance to be running at any given moment. 我希望这个容器在它死后重新启动,但我只需要在任何给定时刻运行一个单独的实例。 Moreover, there's a bunch of environment variables that need to be defined for the server to be correctly configured. 此外,还需要为服务器定义一组环境变量才能正确配置。

I have already created a new cluster. 我已经创建了一个新的集群。 But where do I go from here? 但是我从哪里开始呢? Some tutorials say one should declare pod and service files, but then the next tutorial says one shouldn't declare pods directly but use deployments instead. 一些教程说应该声明pod和服务文件,但是接下来的教程说不应该直接声明pod而是使用部署。 The result is that I'm terribly confused. 结果是我非常困惑。

What's the best approach for this simple use case? 这个简单用例的最佳方法是什么? Also, what is the recommended documentation for using Kubernetes in Google Cloud? 另外,在Google Cloud中使用Kubernetes的推荐文档是什么? (Google's official docs seem out of date.) (谷歌的官方文档似乎已经过时了。)

Based on your description, I would suggest you use a Deployment with replicas set to 1. The Deployment will ensure that there is always one instance of your pod running. 根据您的描述,我建议您使用部署replicas的部署为1.部署将确保始终有一个pod实例正在运行。 You can define your environment variables in the pod template spec of your Deployment manifest. 您可以在部署清单的pod模板规范中定义环境变量

In the documentation, you might also see suggestions to use replication controllers for the same purpose. 在文档中,您可能还会看到将复制控制器用于相同目的的建议。 This is definitely an option but Deployments are considered the successor to replication controllers and are usually recommended at this point. 这绝对是一个选项,但Deployments被认为是复制控制器的后继者 ,通常建议此时使用。

A bare pod is not intended to be durable and will not be restarted in the case of a node failure or other type of eviction. 裸露的吊舱不是持久的,并且在节点故障或其他类型的驱逐的情况下不会重新启动。

The documentation is out-of-date in many places but, as far as I know, the authoritative location (even for GKE) is http://kubernetes.io/docs/ . 文档在很多地方已经过时了,但据我所知,权威地点(即使是GKE)也是http://kubernetes.io/docs/

@ryan 's answer is totally clear. @ryan的回答非常明确。

To have a pod that is durable, one must create it using Deployments. 要拥有一个持久的pod,必须使用Deployments创建它。

A Deployment is generally preferable because it defines a ReplicaSet to ensure that the desired number of Pods is always available and specifies a strategy to replace Pods, in your case, it is one . 部署通常是首选,因为它定义了ReplicaSet以确保所需数量的Pod始终可用,并指定替换Pod的策略,在您的情况下,它是一个

If you create a pod directly without Deployment , you will have to create and manage the pods manually . 如果直接创建Pod而不进行部署 ,则必须手动创建和管理pod。
Objects of kind Pod will not be rescheduled (or self-healed) in the event of a node failure or pod termination. 如果节点发生故障或终端终止,则不会重新安排(或自我修复)类型Pod的对象。

You can use replica set instead, but it is less flexible than the Deployment. 您可以使用replica set ,但它不如部署灵活。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM