【问题标题】:Need to run copy script that will copy some files to mounted path [init-container]需要运行复制脚本,将一些文件复制到安装路径 [init-container]
【发布时间】:2019-03-27 19:58:41
【问题描述】:

我有 tomcat 作为 docker 镜像。 我有 3 个 xmls/property 文件来在我的 tomcat 中引发战争 我需要编写初始化容器

  1. 有一个脚本 [shell 或 python]
  2. 创建一个卷并将其挂载到主容器
  3. 将属性文件从我的本地系统复制到挂载 音量。
  4. 然后 init-container 完成应用容器在此之后启动。

例如: 在我的本地,我有以下内容:

/work-dir tree
├── bootstrap.properties
├── index.html
├── indexing_configuration.xml
├── repository.xml
└── wrapper.sh

init 容器应该运行一个脚本 wrapper.sh 来复制这些
文件到应用容器上的已安装卷中 这是/usr/share/jack-configs/

【问题讨论】:

  • 到目前为止你做了什么尝试,你到底卡在哪里了?
  • 这听起来像是对 ConfigMap 的开箱即用,而不是您尝试对 init 容器执行的操作。

标签: kubernetes


【解决方案1】:

您必须创建一个卷并安装在两个容器上。在 Init 容器上运行脚本以将文件复制到已安装的卷。

我建议您使用 blob 存储来复制文件,而不是使用本地文件,这样会更简单。

This docs 展示了如何做你想做的事。

YAML 示例如下:

apiVersion: v1
kind: Pod
metadata:
  name: init-demo
spec:
  containers:
  - name: nginx
    image: nginx
    ports:
    - containerPort: 80
    volumeMounts:
    - name: workdir
      mountPath: /usr/share/nginx/html
  # These containers are run during pod initialization
  initContainers:
  - name: install
    image: busybox
    command:
    - wget
    - "-O"
    - "/work-dir/index.html"
    - http://kubernetes.io
    volumeMounts:
    - name: workdir
      mountPath: "/work-dir"
  dnsPolicy: Default
  volumes:
  - name: workdir
    emptyDir: {}

要完成你想要的,你必须改变 init 容器中的command 来执行你的脚本,这一点我让你试试。

PS:如果你真的想从本地(节点)文件系统复制,你需要将另一个卷挂载到 init 容器并从一个卷复制到另一个

【讨论】:

  • 是的,我正在探索那个位...更改 wget 以复制命令或在此处嵌入脚本
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多