我有一个 python 应用程序,它的 docker build 大约需要 15-20 分钟。
这是我的 Dockerfile 或多或少的样子
FROM ubuntu:18.04
...
COPY . /usr/local/app
RUN pip install -r /usr/local/app/requirements.txt
...
CMD ...
现在,如果我使用 skaffold,任何代码更改都会触发重建,并且它将重新安装所有要求(从 COPY 步骤开始,其他所有内容都将被重建),无论它们是否已经安装。 iIn docker-compose 这个问题将使用卷来解决。在 Kubernetes 中,如果我们按以下方式使用卷:
apiVersion: v1
kind: Pod
metadata:
name: test
spec:
containers:
- image: test:test
name: test-container
volumeMounts:
- mountPath: /usr/local/venv # this is the directory of the
# virtualenv of python
name: test-volume
volumes:
- name: test-volume
awsElasticBlockStore:
volumeID: <volume-id>
fsType: ext4
skaffold 会解决这个额外的需求构建吗?
最佳答案
我不能专门为 skaffold 说话,但可以改进容器镜像构建。如果有可用的层缓存,则仅在您的 requirements.txt
时重新安装依赖项。变化。这记录在“添加或复制”Best Practices .
FROM ubuntu:18.04
...
COPY requirements.txt /usr/local/app/
RUN pip install -r /usr/local/app/requirements.txt
COPY . /usr/local/app
...
CMD ...
如果模块版本定义松散并说您想要新的补丁版本,您可能需要触发更新。我发现要求应该是具体的,因此版本不会在您不知情/测试的情况下滑到您的应用程序下方。
Kaniko 集群内构建
对于 kaniko 构建以使用默认情况下没有持久存储的集群中的缓存,kaniko 需要安装持久卷(
--cache-dir
)或具有可用层的容器镜像存储库( --cache-repo
)。
关于kubernetes - 如何将 Skaffold 与 kubernetes 卷一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57699128/