# rapids-notebook.yaml (extended)
apiVersion: v1
kind: ServiceAccount
metadata:
  name: rapids-dask
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: rapids-dask
rules:
  - apiGroups: [""]
    resources: ["events"]
    verbs: ["get", "list", "watch"]
  - apiGroups: [""]
    resources: ["pods", "services"]
    verbs: ["get", "list", "watch", "create", "delete"]
  - apiGroups: [""]
    resources: ["pods/log"]
    verbs: ["get", "list"]
  - apiGroups: [kubernetes.dask.org]
    resources: ["*"]
    verbs: ["*"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: rapids-dask
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: rapids-dask
subjects:
  - kind: ServiceAccount
    name: rapids-dask
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: jupyter-server-proxy-config
data:
  jupyter_server_config.py: |
    c.ServerProxy.host_allowlist = lambda app, host: True
---
apiVersion: v1
kind: Service
metadata:
  name: rapids-notebook
  labels:
    app: rapids-notebook
spec:
  type: ClusterIP
  ports:
    - port: 8888
      name: http
      targetPort: notebook
  selector:
    app: rapids-notebook
---
apiVersion: v1
kind: Pod
metadata:
  name: rapids-notebook
  labels:
    app: rapids-notebook
spec:
  serviceAccountName: rapids-dask
  securityContext:
    fsGroup: 0
  containers:
    - name: rapids-notebook
      image: us-central1-docker.pkg.dev/nv-ai-infra/rapidsai/rapidsai/base:23.08-cuda12.0-py3.10
      resources:
        limits:
          nvidia.com/gpu: 1
      ports:
        - containerPort: 8888
          name: notebook
      env:
        - name: DASK_DISTRIBUTED__DASHBOARD__LINK
          value: "/proxy/{host}:{port}/status"
      volumeMounts:
        - name: jupyter-server-proxy-config
          mountPath: /root/.jupyter/jupyter_server_config.py
          subPath: jupyter_server_config.py
  volumes:
    - name: jupyter-server-proxy-config
      configMap:
        name: jupyter-server-proxy-config
