MaxKB icon indicating copy to clipboard operation
MaxKB copied to clipboard

[BUG]集群部署后无法登录

Open rainbowers opened this issue 2 years ago • 7 comments

联系方式

[email protected]

MaxKB 版本

v1.1.3

问题描述

pgsql已在容器之外单独部署,maxkb部署在k8s中,连接的是容器之外的pgsql,容器内pgsql已关闭,启用多pod时,一直无法登录,后台日志显示:[log WARNING] Unauthorized: /api/user,[basehttp WARNING] "GET /api/user HTTP/1.1" 401 127

重现步骤

pgsql已在容器之外单独部署,maxkb部署在k8s中,连接的是容器之外的pgsql,容器内pgsql已关闭,启用多pod时,一直无法登录,后台日志显示:[log WARNING] Unauthorized: /api/user,[basehttp WARNING] "GET /api/user HTTP/1.1" 401 127

期待的正确结果

实现在k8s中集群化部署、pgsql独立部署,提高并发及稳定性

相关日志输出

[root@k8s-master1 yaml]# kubectl get pod,deploy -n maxkb -o wide
NAME                         READY   STATUS    RESTARTS   AGE    IP          NODE          NOMINATED NODE   READINESS GATES
pod/maxkb-66d564f465-kkjhr   1/1     Running   0          15m    20.0.4.26   k8s-worker2   <none>           <none>
pod/maxkb-66d564f465-pb5w8   1/1     Running   0          154m   20.0.4.23   k8s-worker2   <none>           <none>

NAME                    READY   UP-TO-DATE   AVAILABLE   AGE    CONTAINERS   IMAGES                                   SELECTOR
deployment.apps/maxkb   2/2     2            2           170m   maxkb        harbor.wingtech.com/library/maxkb:v1.0   app=maxkb

[root@k8s-master1 yaml]# kubectl logs pod/maxkb-66d564f465-kkjhr -n maxkb
Building prefix dict from the default dictionary ...
DEBUG:jieba:Building prefix dict from the default dictionary ...
Loading model from cache /tmp/jieba.cache
DEBUG:jieba:Loading model from cache /tmp/jieba.cache
Loading model cost 0.630 seconds.
DEBUG:jieba:Loading model cost 0.630 seconds.
Prefix dict has been built successfully.
DEBUG:jieba:Prefix dict has been built successfully.
Operations to perform:
  Apply all migrations: application, contenttypes, dataset, django_apscheduler, embedding, setting, users
Running migrations:
  No migrations to apply.
  Your models in app(s): 'application' have changes that are not yet reflected in a migration, and so won't be applied.
  Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.
Building prefix dict from the default dictionary ...
DEBUG:jieba:Building prefix dict from the default dictionary ...
Loading model from cache /tmp/jieba.cache
DEBUG:jieba:Loading model from cache /tmp/jieba.cache
Loading model cost 0.538 seconds.
DEBUG:jieba:Loading model cost 0.538 seconds.
Prefix dict has been built successfully.
DEBUG:jieba:Prefix dict has been built successfully.
Operations to perform:
  Apply all migrations: application, contenttypes, dataset, django_apscheduler, embedding, setting, users
Running migrations:
  No migrations to apply.
  Your models in app(s): 'application' have changes that are not yet reflected in a migration, and so won't be applied.
  Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.
2024-06-03 13:41:30 [log WARNING] Unauthorized: /api/user/logout
2024-06-03 13:41:30 [basehttp WARNING] "POST /api/user/logout HTTP/1.1" 401 127
2024-06-03 13:41:42 [log WARNING] Unauthorized: /api/user
2024-06-03 13:41:42 [basehttp WARNING] "GET /api/user HTTP/1.1" 401 127
2024-06-03 13:41:44 [log WARNING] Unauthorized: /api/user
2024-06-03 13:41:44 [basehttp WARNING] "GET /api/user HTTP/1.1" 401 127

附加信息

No response

rainbowers avatar Jun 03 '24 06:06 rainbowers

Have you tried to set .spec.sessionAffinity to ClientIP for the Service (default is None)?

liqiang-fit2cloud avatar Jun 03 '24 06:06 liqiang-fit2cloud

理论上配置session会话保持是可以的,但验证一下是不行的

rainbowers avatar Jun 03 '24 07:06 rainbowers

那你检查你的配置,理论上对于单个客户端来说,多pod+会话保持,与单pod是一样的。

liqiang-fit2cloud avatar Jun 03 '24 07:06 liqiang-fit2cloud

你先试试单pod。

liqiang-fit2cloud avatar Jun 03 '24 07:06 liqiang-fit2cloud

单pod没问题

rainbowers avatar Jun 03 '24 07:06 rainbowers

那你再检查一下sessionAffinity吧。

liqiang-fit2cloud avatar Jun 03 '24 07:06 liqiang-fit2cloud

Ingress 配置session会话保持可以解决问题,svc 不需要配置sessionAffinity,配置如下:

apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: example-ingress annotations: kubernets.io/ingress.class: "nginx" nginx.ingress.kubernetes.io/rewrite-target: / ingress.kubernetes.io/ssl-redirect: "false" nginx.ingress.kubernetes.io/proxy-body-size: "2048m" nginx.org/client-max-body-size: "2048m" nginx.ingress.kubernetes.io/proxy-connect-timeout: "300" nginx.ingress.kubernetes.io/proxy-send-timeout: "300" nginx.ingress.kubernetes.io/proxy-read-timeout: "300" nginx.ingress.kubernetes.io/affinity: "cookie" nginx.ingress.kubernetes.io/affinity-mode: "persistent" nginx.ingress.kubernetes.io/session-cookie-name: "route" nginx.ingress.kubernetes.io/session-cookie-expires: "14400" nginx.ingress.kubernetes.io/session-cookie-max-age: "14400" spec: rules:

  • host: example.com http: paths:
    • path: / pathType: Prefix backend: service: name: service-name port: number: 80

rainbowers avatar Jun 05 '24 05:06 rainbowers