Kubernetes volumeMount folder and file permissions?

假装没事ソ 提交于 2019-12-11 17:08:15

问题


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.

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.

Here is the architecture diagram:

Below is the Deployment file.

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:


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.

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: {}       


来源:https://stackoverflow.com/questions/55406963/kubernetes-volumemount-folder-and-file-permissions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!