0

I have a working Flask app running uwsgi in Docker. I am trying to migrate this application to Kubernetes. I have the following Nginx configmap. I have created the following service and deployment created. I am missing something to make this work and cant seem to figure out that it is. From the logs of Nginx it doesnt seem to find the sock file. This is the exact error message "connect() to unix:/app/api.sock failed (2: No such file or directory) ". This is what I have checked so far:

  1. I have done a chmod 777 (I know this is bad, but it is just for testing, I will put it back) to the app/api.sock file and it still cant find it.
  2. I know that Flask is running correctly and accepting connections. I can see the Flask banner on the POD logs.
  3. I have verified that the file api.sock is in the /app directory in the Flask POD.

Any other suggestions?

# nginx.conf
server {
  listen 80;
  charset utf-8;
  underscores_in_headers on;

  location / {
    include uwsgi_params;
    uwsgi_pass unix:/app/api.sock;
  }
}
# flask-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: flask-internal-service
spec:
  selector:
    app: api-flask
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
# flask-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: api-flask
spec:
  selector:
    matchLabels:
      app: api-flask
  replicas: 2
  template:
    metadata:
      labels:
        app: api-flask
    spec:
      containers:
        - env:
            - name: CONTAINER
              value: flask
          image: my_registry/api_flask:latest
          name: flask
          stdin: true
          ports:
          - containerPort: 8080
          volumeMounts:
          - name: uwsgi-socket-volume
            mountPath: /app/api.sock
            subPath: api.sock
      volumes:
      - name: uwsgi-socket-volume
        emptyDir: { }
      restartPolicy: Always
Taimoor Mirza
  • 1,093
  • 7
  • 19
user2236794
  • 441
  • 3
  • 7
  • 22

1 Answers1

0

As per jamsesso, it seems that programs that create files in /tmp are the only programs that are able to see the files in that directory that's why nginx can't see the files in socket.

  To resolve the issue, place the socket in a different directory.
Dion V
  • 356
  • 2
  • 7