简体   繁体   English

在Kubernetes中自动生成Pod

[英]Automatically Generate Pods in Kubernetes

I previously created a Flask server that spawns Docker containers using the Docker Python SDK. 我之前创建了一个Flask服务器,该服务器使用Docker Python SDK生成Docker容器。 When a client hits a specific endpoint, the server would generate a container. 当客户端到达特定端点时,服务器将生成一个容器。 It would maintain queues, and it would be able to kill containers that didn't respond to requests. 它可以维护队列,并且可以杀死没有响应请求的容器。

I want to migrate towards Kubernetes, but I am starting to think my current server won't be able to "spawn" jobs as pods automatically like in docker. 我想向Kubernetes迁移,但是我开始认为我当前的服务器将无法像docker中那样自动“生成” pod。

docker.from_env().containers.run('alpine', 'echo hello world')  

Is Docker Swarm a better solution for this, or is there a hidden practice that is done in Kubernetes? Docker Swarm是否是一个更好的解决方案,还是在Kubernetes中进行了隐蔽的实践? Would the Kubernetes Python API be a logical solution for automatically generating pods and jobs, where the Flask server is a pod that manages other pods within the cluster? Kubernetes Python API是否会是自动生成Pod和作业的逻辑解决方案,而Flask服务器是管理集群中其他Pod的Pod?

'Kubectl run' is much like 'docker run' in that it will create a Pod with a container based on a docker image (eg How do i run curl command from within a Kubernetes pod ). 'Kubectl run'与'docker run'非常相似,因为它会基于docker映像创建一个带有容器的Pod(例如, 如何从Kubernetes容器中运行curl命令 )。 See https://kubernetes.io/docs/reference/kubectl/docker-cli-to-kubectl/ for more comparison. 请参阅https://kubernetes.io/docs/reference/kubectl/docker-cli-to-kubectl/了解更多比较。 But what you run with k8s are Pods/Jobs that contain containers rather than running containers directly so this will add an extra layer of complexity for you. 但是,使用k8运行的是包含容器而不是直接运行容器的Pod / Job,因此这将为您增加一层额外的复杂性。

Kubernetes is more about orchestrating services rather than running short-lived jobs. Kubernetes的重点在于协调服务,而不是运行短期任务。 It has some features and can be used to run jobs but that isn't its central focus. 它具有一些功能,可用于运行作业,但这不是其重点。 If you're going in that direction you may want to look at knative (and knative build) or kubeless as what you describe sounds rather like the serverless concept. 如果您朝着这个方向发展,那么您可能想看一下knative(和knative构建)或kubeless,因为您所描述的听起来很像无服务器概念。 Or if you are thinking more about Jobs then perhaps brigade ( https://brigade.sh ). 或者,如果您想更多地考虑乔布斯,那么也许是旅( https://brigade.sh )。 (For more see https://www.quora.com/Is-Kubernetes-suited-for-long-running-batch-jobs ) If you are looking to run web app workloads that serve requests then note that you don't need to kill containers that fail to respond on k8s as k8s will monitor and restart them for you. (有关更多信息,请参见https://www.quora.com/Is-Kubernetes-suited-for-long-running-batch-jobs )。如果您要运行可处理请求的Web应用程序工作负载,请注意不需要杀死无法在k8s上响应的容器,因为k8s将为您监视并重新启动它们。

I don't know swarm well enough to compare. 我不知道有很多人可以比较。 I suspect it would be a bit easier for you as it is aimed more centrally at docker (the k8s API is intended to support other runtimes) but perhaps somebody else can comment on that. 我怀疑这对您来说会容易一些,因为它更集中于docker(k8s API旨在支持其他运行时),但是也许其他人可以对此发表评论。 Whether using swarm instead helps you will I guess depend on your motivations. 我猜想使用群体是否对您有帮助,取决于您的动机。

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

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