简体   繁体   English

python 应用程序调用 kubernetes 以编程方式创建 pod

[英]python app to call kubernetes to create pod programmatically

I am designing a web application where users can have trade bots running.我正在设计一个 web 应用程序,用户可以在其中运行交易机器人。 So they will sign in, pay for membership then they will create a bot, enter the credentials and start the bot.所以他们将登录,支付会员费用,然后他们将创建一个机器人,输入凭据并启动机器人。 The user can stop / start the trade bot.用户可以停止/启动交易机器人。

I am trying to do this using kubernetes, so I will have everything running on kubernetes.我正在尝试使用 kubernetes 来执行此操作,因此我将在 kubernetes 上运行所有内容。 I will create a namespace named bots and all bots for all clients will be running inside this bot namespace.我将创建一个名为 bots 的命名空间,所有客户端的所有 bot 都将在此 bot 命名空间内运行。

Stack is: python (django framework ) + mysql + aws + kubernetes堆栈为:python(django 框架)+ mysql + aws + kubernetes

question: Is there a way to programmatically create a pod using python?问题:有没有办法使用 python 以编程方式创建 pod? I want to integrate with the application code.我想与应用程序代码集成。 So when user clicks on create new bot it will start a new pod running with all the parameters for the specific user.因此,当用户单击创建新机器人时,它将启动一个新的 pod,其中包含特定用户的所有参数。

Basically each pod will be a tenant.基本上每个 pod 都是租户。 But a tenant can have multiple pods / bots.但是一个租户可以有多个 Pod/机器人。 So how do that?那么怎么做呢? Is there any kubernetes python lib that does it?是否有任何 kubernetes python 库可以做到这一点? I did some online search but didn't find anything.我做了一些在线搜索,但没有找到任何东西。 Thanks谢谢

you can use the official Python Kubernetes client to create and manage the POD across the cluster programmatically.您可以使用官方 Python Kubernetes 客户端以编程方式跨集群创建和管理 POD。

https://github.com/kubernetes-client/python https://github.com/kubernetes-client/python

You can keep one YAML file and replace the values into as per requirement like Deployment Name , Ports and apply the files to the cluster it will create the POD with base image.您可以保留一个 YAML 文件,并根据部署名称、端口等要求将值替换为部署名称端口并将文件应用到集群,它将使用基本映像创建 POD。

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

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