无法将 kubernetes 持久卷分配给 uwsgi 应用程序
Can't assign kubernetes persistent volume to uwsgi application
尝试将持久卷分配给 uWSGI 应用程序,但出现以下错误:bind(): Operation not permitted [core/socket.c line 230]
。
当我分配 none-persistent "empty dir" 卷时有效。
这是我要分配的持久卷的 yaml 文件:
#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
应用程序的清单如下所示:
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
最终目标是从 uWSGI 收集指标,此时,如果 pod 被缩减删除,指标也会被删除
为了解决这个问题,我必须先创建实际的文件夹,在我的例子中 /storage
,在 Dockerfile 中,同时构建应用程序映像,所以我添加了 RUN mkdir /storage
到 Dockerfile
尝试将持久卷分配给 uWSGI 应用程序,但出现以下错误:bind(): Operation not permitted [core/socket.c line 230]
。
当我分配 none-persistent "empty dir" 卷时有效。
这是我要分配的持久卷的 yaml 文件:
#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
应用程序的清单如下所示:
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
最终目标是从 uWSGI 收集指标,此时,如果 pod 被缩减删除,指标也会被删除
为了解决这个问题,我必须先创建实际的文件夹,在我的例子中 /storage
,在 Dockerfile 中,同时构建应用程序映像,所以我添加了 RUN mkdir /storage
到 Dockerfile