在kubernetes中创建一个pod /容器-如何将一堆文件复制到其中

时间:2019-01-30 17:32:39

标签: kubernetes

抱歉,这是一个菜鸟问题:

我正在使用Pod定义yaml文件在kubernetes集群中创建Pod。

此吊舱仅定义一个容器。我想...将一些文件复制到容器中的特定目录。

类似于docker-compose:

volumes:
      - ./testHelpers/certs:/var/private/ssl/certs

在这一点(定义吊舱的位置)是否可以这样做

如果没有,我的替代品是什么?

PS-我知道docker-compose中的示例非常不同,因为它将本地目录映射到容器中的目录

2 个答案:

答案 0 :(得分:2)

最好在容器定义中使用卷。 Initialize the pod before the container runs

除此之外,您还可以使用ConfigMap存储所需的证书和其他配置文件,然后可以将它们作为卷在容器中访问。 More details here

答案 1 :(得分:1)

您应该创建一个配置映射,可以从文件或目录中完成。

kubectl create configmap my-config --from-file=configuration/

然后将配置映射安装为目录:

apiVersion: v1
kind: Pod
metadata:
  name: configmap-pod
spec:
  containers:
    - name: test
      image: busybox
      volumeMounts:
        - name: my-config
          mountPath: /etc/config
  volumes:
    - name: my-config
      configMap:
        name: my-config
相关问题