将带有初始化的docker run命令转换为多容器k8s pod或撰写 [英] Translate docker run commands with initialization to a multi-container k8s pod or compose

查看:200
本文介绍了将带有初始化的docker run命令转换为多容器k8s pod或撰写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要为k8s yaml配置的容器.使用终端在docker run上的工作流程如下:

I have a container that I need to configure for k8s yaml. The workflow on docker run using the terminal looks like this.:

docker run -v $(pwd):/projects \
             -w /projects \
             gcr.io/base-project/myoh:v1 init *myproject*

此命令创建一个名为 myproject 的目录.要完成工作流程,我需要进入此 myproject 文件夹并运行:

This command creates a directory called myproject. To complete the workflow, I need to cd into this myproject folder and run:

docker run -v $(pwd):/project \
             -w /project \
             -p 8081:8081 \
             gcr.io/base-project/myoh:v1

有人知道如何将其转换为docker-compose或k8s pods/deployment yaml吗?我尝试了所有想到的方法,但都没有成功.

Any idea how to convert this to either a docker-compose or a k8s pods/deployment yaml? I have tried all that come to mind with no success.

推荐答案

当前目录的绑定安装根本无法转换为Kubernetes.无法将Pod的文件系统连接回本地工作站.标准的Kubernetes设置具有多节点安装,并且如果可以直接连接到节点(可能不是),则无法预测Pod将在哪个节点上运行,并且将代码复制到每个节点上既麻烦又困难保持.如果您使用的是托管的Kubernetes安装(例如GKE),则群集自动缩放器甚至可能会自动创建和删除节点,并且您将没有机会手动复制内容.

The bind mount of the current directory can't be translated to Kubernetes at all. There's no way to connect a pod's filesystem back to your local workstation. A standard Kubernetes setup has a multi-node installation, and if it's possible to directly connect to a node (it may not be) you can't predict which node a pod will run on, and copying code to every node is cumbersome and hard to maintain. If you're using a hosted Kubernetes installation like GKE, it's even possible that the cluster autoscaler will create and delete nodes automatically, and you won't have an opportunity to manually copy things in.

您需要将应用程序代码构建到自定义映像中.这样可以设置所需的WORKDIRCOPY代码以及RUN所需的任何设置命令.然后,您需要将其推送到图像存储库,例如GCR

You need to build your application code into a custom image. That can set the desired WORKDIR, COPY the code in, and RUN any setup commands that are required. Then you need to push that to an image repository, like GCR

docker build -t gcr.io/base-project/my-project:v1 .
docker push gcr.io/base-project/my-project:v1

一旦有了,就可以创建一个最小的Kubernetes 部署运行它.将您构建并推送的图像的GCR名称设置为其image:.您还需要一个服务,即使从其他Pod都可以访问它在同一群集中.

Once you have that, you can create a minimal Kubernetes Deployment to run it. Set the GCR name of the image you built and pushed as its image:. You will also need a Service to make it accessible, even from other Pods in the same cluster.

这篇关于将带有初始化的docker run命令转换为多容器k8s pod或撰写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆