Can't assign kubernetes persistent volume to uwsgi application

5/31/2019

Trying to assign persistent volume to an uWSGI application, but I'm getting following error: bind(): Operation not permitted [core/socket.c line 230]. Works when I assign none-persistent "empty dir" volume.

Here are the yaml files of the persistent volume I'm trying to assign:

#volume claim
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: api-storage
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: api-storage
  resources:
    requests:
      storage: 100Gi
#storage class
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: api-storage
provisioner: kubernetes.io/azure-file
mountOptions:
  - dir_mode=0777
  - file_mode=0777
  - uid=root
  - gid=root
parameters:
  skuName: Standard_LRS

The manifest of the application looks like this :

apiVersion: apps/v1
kind: Deployment
metadata:
  name: api-app
spec:
  replicas: 2
  selector:
    matchLabels:
      app: api-app
  template:
    metadata:
      labels:
        app: api-app
    spec:
      containers:
      - name: nginx
        image: nginx
        lifecycle:
          preStop:
            exec:
              command: ["/usr/sbin/nginx","-s","quit"]
        ports:
          - containerPort: 80
            protocol: TCP
        resources:
          limits:
            cpu: 50m
            memory: 100Mi
          requests:
            cpu: 10m
            memory: 50Mi
        volumeMounts:
          - name: storage
            mountPath: /var/run/api
          - name: nginx-conf
            mountPath: /etc/nginx/conf.d
      - name: api-app
        image: azurecr.io/api_api_se:opencv
        workingDir: /app
        command: ["/usr/local/bin/uwsgi"]
        args:
          - "--die-on-term"
          - "--manage-script-name"
          - "--mount=/=api:app_dispatch"
          - "--socket=/var/run/api/uwsgi.sock"
          - "--chmod-socket=777"
          - "--pyargv=se"
          # - "--metrics-dir=/storage"
          # - "--metrics-dir-restore"
        resources:
          requests:
            cpu: 150m
            memory: 1Gi
        volumeMounts:
          - name: storage
            mountPath: /var/run/api
          # - name: storage
          #   mountPath: /storage
      volumes:
        - name: storage  
# work's if following two lines are substituted with "emptyDir: {}"
          persistentVolumeClaim:
            claimName: api-storage
        - name: nginx-conf
          configMap:
            name: api
      tolerations:
      - key: "sku"
        operator: "Equal"
        value: "test"
        effect: "NoSchedule"
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: api-app
  name: api-app
spec:
  ports:
    - port: 80
      protocol: TCP
      targetPort: 80
  selector:
    app: api-app

The final goal is to collect metrics from the uWSGI, at this moment, the metrics get delete if the pod gets deleted by scale down

-- user1334557
kubernetes
persistent-volumes
uwsgi

1 Answer

6/27/2019

To solve this problem I had to create the actual folder first, in my case /storage, in the Dockerfile while building the application image, so I added RUN mkdir /storage to the Dockerfile

-- user1334557
Source: StackOverflow