Kubernetes volumeMount文件夹和文件权限? [英] Kubernetes volumeMount folder and file permissions?

查看:3560
本文介绍了Kubernetes volumeMount文件夹和文件权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试将配置文件从hostPath挂载到kubernetes容器.使用minikube和VirtualBox共享文件夹可以使用此功能,但是我无法在Linux上使用它.

Trying to mount config files from a hostPath to a kubernetes container. This works using minikube and VirtualBox shared folder, but I am unable to make this work on Linux.

我使用AWS EKS和以下架构 https://aws. amazon.com/quickstart/architecture/amazon-eks/.我认为我的问题是文件需要存在于每个EKS Node实例上.

I making use of AWS EKS and the following architecture https://aws.amazon.com/quickstart/architecture/amazon-eks/. I think my problem is that the files need to live on each of the EKS Node instances.

这是体系结构图:

下面是部署文件.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: openhim-core-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      component: openhim-core
  template:
    metadata:
      labels:
        component: openhim-core
    spec:
      volumes:
        - name: core-config
          hostPath:
            path: /var/config/openhim-core
      containers:
        - name: openhim-core
          image: jembi/openhim-core:5.rc
          ports:
            - containerPort: 8080
            - containerPort: 5000
            - containerPort: 5001
          volumeMounts:
            - name: core-config
              mountPath: /usr/src/app/config
          env:
            - name: NODE_ENV
              value: development

推荐答案

经过一番痛苦之后,我发现我试图将配置放在可以访问kubectl的Linux Bastion主机上,但是实际上,这种配置必须是在每个可用区中的每个EC2实例上.

After much pain I found that I am trying to place the configuration on the Linux Bastion host where I have access to kubectl but in fact this configuration will have to be on each of the EC2 instances in every availability zone.

对我来说,解决方案是使用initContainer.

The solution for me was to make use of a initContainer.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: openhim-core-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      component: openhim-core
  template:
    metadata:
      labels:
        component: openhim-core
    spec:
      volumes:
        - name: core-config
          hostPath:
            path: /var/config/openhim-core
      containers:
        - name: openhim-core
          image: jembi/openhim-core:5
          ports:
            - containerPort: 8080
            - containerPort: 5000
            - containerPort: 5001
          volumeMounts:
            - name: core-config
              mountPath: /usr/src/app/config
          env:
            - name: NODE_ENV
              value: development
      initContainers:
        - name: install
          image: busybox
          command:
          - wget
          - "-O"
          - "/usr/src/app/config/development.json"
          - https://s3.eu-central-1.amazonaws.com/../development.json
          volumeMounts:
            - name: core-config
              mountPath: "/usr/src/app/config"      
      volumes:
        - name: core-config
          emptyDir: {}       

这篇关于Kubernetes volumeMount文件夹和文件权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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