Kubernetes + Nginx의 Jupyterhub-로그인 후 생성되지 않음

Aug 21 2020

컨텍스트 : Terraform을 사용하여 AWS에서 EKS 클러스터를 생성했습니다. 해당 클러스터에서 Helm 3을 사용하여 Nginx Ingress를 설치했습니다. TLS는 Let 's Encrypt와 cert-manager를 사용하여 수행됩니다. 이후 배포, 서비스 및 수신 yaml 파일을 사용하여 웹 노출 애플리케이션을 추가 할 수 있습니다.

문제 : 나를 위해 작동하지 않는 것이 JupyterHub를 성공적으로 배포하는 것입니다. TCP 프로토콜을 사용하는 JupyterHub와 인증서를 성공적으로 생성하는 cert-manager를 사용하면 설치 및 노출이 제대로 작동합니다. 사용자가 jupyterhub에 성공적으로 로그인하면 문제가 시작되지만 invalid or expired cookie tokenjupyterhub가 노트북을 생성해야 할 때 발생합니다.

질문 : 스폰이 작동하지 않는 이유와 해결 방법이 확실하지 않습니다. 누구든지 문제를 더 잘 이해할 수있는 제안이 있습니까?

jupyterhub_config.py다음과 같습니다 :

c = get_config()
c.JupyterHub.authenticator_class = 'jupyterhub.auth.DummyAuthenticator'
c.Authenticator.allowed_users = {'dummy'}
c.Authenticator.admin_users = {'dummy'}
c.DummyAuthenticator.password = "fakenews"
c.JupyterHub.admin_access = True

deployment.yaml다음과 같습니다 :

---
apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "1"
  generation: 1
  labels:
    run: jupyterhub
  name: jupyterhub
  namespace: jhub
spec:
  progressDeadlineSeconds: 600
  replicas: 2
  revisionHistoryLimit: 2
  selector:
    matchLabels:
      run: jupyterhub
  template:
    metadata:
      creationTimestamp: ~
      labels:
        run: jupyterhub
    spec:
      containers:
        - name: jupyterhub
          image: "jupyterhub/jupyterhub:latest"
          imagePullPolicy: IfNotPresent
          ports:
            -
              containerPort: 8000
              protocol: TCP
          terminationMessagePolicy: File
          volumeMounts:
            -
              mountPath: /srv/jupyterhub/jupyterhub_config.py
              name: jupyterhub-config
              subPath: jupyterhub_config.py
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
      volumes:
        -
          configMap:
            name: jupyterhub-config
          name: jupyterhub-config

ingress.yaml다음과 같습니다 :

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-resource
  annotations:
    kubernetes.io/ingress.class: nginx
    cert-manager.io/cluster-issuer: "letsencrypt-prod"
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
  tls:
  - hosts:
    - hub.example.com
    secretName: hub-example-com-tls
  rules:
  - host: hub.example.com
    http:
      paths:
      - path: /
        backend:
          serviceName: jupyterhub
          servicePort: 8000

사용 된 명령 :

$ kubectl create configmap jupyterhub-config --from-file=./jupyterhub_config.py $ kubectl create -f deployment.yaml
$ kubectl expose deployment jupyterhub $ kubectl apply -f ingress.yaml

이로 인해에서 성공적인 보안 배포 웹 서비스가 생성됩니다 https://hub.example.com. 그러나 로그인 후 invalid or expired cookie tokenjupyter 인스턴스를 생성하려고 할 때 jupyterhub 컨테이너 로그에서를 제공 합니다.

[I 2020-08-21 08:26:42.725 JupyterHub app:2307] Running JupyterHub version 1.2.0dev
[I 2020-08-21 08:26:42.726 JupyterHub app:2338] Using Authenticator: jupyterhub.auth.DummyAuthenticator-1.2.0dev
[I 2020-08-21 08:26:42.726 JupyterHub app:2338] Using Spawner: jupyterhub.spawner.LocalProcessSpawner-1.2.0dev
[I 2020-08-21 08:26:42.726 JupyterHub app:2338] Using Proxy: jupyterhub.proxy.ConfigurableHTTPProxy-1.2.0dev
[I 2020-08-21 08:26:42.735 JupyterHub app:1442] Writing cookie_secret to /srv/jupyterhub/jupyterhub_cookie_secret
[I 2020-08-21 08:26:42.752 alembic.runtime.migration migration:155] Context impl SQLiteImpl.
[I 2020-08-21 08:26:42.752 alembic.runtime.migration migration:162] Will assume non-transactional DDL.
[I 2020-08-21 08:26:42.758 alembic.runtime.migration migration:515] Running stamp_revision  -> 4dc2d5a8c53c
[I 2020-08-21 08:26:42.809 JupyterHub proxy:461] Generating new CONFIGPROXY_AUTH_TOKEN
[I 2020-08-21 08:26:42.850 JupyterHub app:2377] Initialized 0 spawners in 0.002 seconds
[W 2020-08-21 08:26:42.853 JupyterHub proxy:643] Running JupyterHub without SSL.  I hope there is SSL termination happening somewhere else...
[I 2020-08-21 08:26:42.853 JupyterHub proxy:646] Starting proxy @ http://:8000
08:26:43.359 [ConfigProxy] info: Proxying http://*:8000 to (no default)
08:26:43.362 [ConfigProxy] info: Proxy API at http://127.0.0.1:8001/api/routes
08:26:43.474 [ConfigProxy] info: 200 GET /api/routes 
[I 2020-08-21 08:26:43.475 JupyterHub app:2622] Hub API listening on http://127.0.0.1:8081/hub/
08:26:43.476 [ConfigProxy] info: 200 GET /api/routes 
[I 2020-08-21 08:26:43.476 JupyterHub proxy:320] Checking routes
[I 2020-08-21 08:26:43.476 JupyterHub proxy:400] Adding default route for Hub: / => http://127.0.0.1:8081
08:26:43.478 [ConfigProxy] info: Adding route / -> http://127.0.0.1:8081
08:26:43.478 [ConfigProxy] info: Route added / -> http://127.0.0.1:8081
08:26:43.478 [ConfigProxy] info: 201 POST /api/routes/ 
[I 2020-08-21 08:26:43.479 JupyterHub app:2697] JupyterHub is now running at http://:8000
[I 2020-08-21 08:26:56.023 JupyterHub log:181] 302 GET /hub/ -> /hub/login (@10.0.1.148) 1.16ms
[I 2020-08-21 08:27:01.409 JupyterHub base:742] User logged in: dummy
[I 2020-08-21 08:27:01.429 JupyterHub log:181] 302 POST /hub/login?next= -> /hub/spawn ([email protected]) 68.74ms
[I 2020-08-21 08:27:01.758 JupyterHub log:181] 200 GET /hub/login?next=%2Fhub%2Fspawn (@10.0.1.148) 219.05ms
08:31:43.482 [ConfigProxy] info: 200 GET /api/routes 
[I 2020-08-21 08:31:43.482 JupyterHub proxy:320] Checking routes
[I 2020-08-21 12:06:43.482 JupyterHub proxy:320] Checking routes
[I 2020-08-21 12:07:08.386 JupyterHub log:181] 200 GET /hub/login?next=%2Fhub%2Fspawn (@10.0.2.117) 1.85ms
[I 2020-08-21 12:07:13.216 JupyterHub base:742] User logged in: dummy
[I 2020-08-21 12:07:13.217 JupyterHub log:181] 302 POST /hub/login?next=%2Fhub%2Fspawn -> /hub/spawn ([email protected]) 5.40ms
[I 2020-08-21 12:07:13.309 JupyterHub log:181] 200 GET /hub/login?next=%2Fhub%2Fspawn (@10.0.2.117) 1.22ms
[I 2020-08-21 13:27:28.324 JupyterHub log:181] 302 GET / -> /hub/ (@10.0.2.117) 0.90ms 
[I 2020-08-21 13:27:28.410 JupyterHub log:181] 200 GET /hub/login (@10.0.2.117) 1.28ms 
[W 2020-08-21 13:27:34.613 JupyterHub base:392] Invalid or expired cookie token 
[I 2020-08-21 13:27:34.615 JupyterHub log:181] 302 GET /hub/spawn -> /hub/login?next=%2Fhub%2Fspawn (@10.0.2.117) 1.88ms

답변

1 Matt Aug 24 2020 at 14:22

OP가 언급했듯이 배포를 1 개의 복제본으로 축소하면 문제가 해결되었습니다.

무엇이 문제인지 명확히하고 싶습니다.

Jupyterhub는 확장 가능하지 않습니다. 상태 저장 응용 프로그램이며 (현재로서는) 고 가용성으로 실행하는 것이 불가능합니다.

K8s 서비스는 두 개의 포드 / 복제본간에 부하를 분산하여 트래픽을 무작위로 전송합니다.

하나의 jupyterhub에 로그인하면 토큰을받습니다. 이제이 토큰으로 다른 요청을 보냅니다. 방금받은 토큰이 포함 된이 요청이 jupyterhub의 두 번째 인스턴스로 전송되면 어떻게 될지 짐작할 수 있습니까? 이 토큰이 생성 된 토큰이 아니기 때문에이 토큰이 무엇인지 모르는 사람입니다.

invalid or expired cookie token

이것이 당신이 보게 될 것입니다. 두 번째 인스턴스는이 토큰이 유효하지 않음을 발견합니다.

이것이 하나의 복제본으로 축소하여 문제를 해결 한 이유입니다. 이제 모든 트래픽이 하나의 포드로 전송되기 때문입니다.

aptroost Aug 24 2020 at 08:14

복제본 수를 2에서 1로 변경하면이 문제가 해결되었습니다. 감사! 이것은 복제본에서 작동하지 않는다는 점에 매우 유감입니다.