Kubernetes volumeMount文件夹和文件权限?

时间:2019-03-28 21:16:21

标签: kubernetes amazon-eks

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

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

这是架构图: enter image description here

下面是部署文件。

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

1 个答案:

答案 0 :(得分:0)

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

对我来说,解决方案是使用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: {}