cdmikechen opened a new issue #853:
URL: https://github.com/apache/submarine/issues/853


   由于篇幅问题,考虑到英文可能不一定能表达清楚很多执行的细节,暂时以中文进行描述。
   
   目前的 Submarine 每次创建一个新的 NoteBook 都会在 K8s 的CRD资源上创建一个新的实例。基于 
`notebook-controller` 的服务发现的机制,会创建一个 Jupyter 的 Statefuleset 资源和 Service 
资源。这是一个正常的处理流程,用户在 NoteBook 启动后可在 Submarine 上点击名称访问这个实例。
   但是每一个实例在不同的使用者创建并使用后并不是一直在运行代码的,很多情况下在执行了一个idea或者验证了一些预想的情景和数据后,这个 NoteBook 
实例就会被搁置。虽然用户稍后退出了 Submarine,但是这个实例仍然存在,这对于集群来讲就是一个被占用的无用的 Pod。
   
   我目前的考虑是希望 Submarine 能提供一个针对 NoteBook 启动和停止的功能,这个功能会分为2个部分来实现。
   1. 在目前 NoteBook 功能的列表操作部分添加 `启动/停止` 按钮。用户在确认不使用该 NoteBook 时候可关闭 Pod,但是相关的 
workspace 等资源不进行回收;再次启用后可继承原来的资源重启服务。
   2. 确认一种自动停止的机制,在用户指定时间不操作后,Submarine 自动停止该实例。在用户再次需要时可再启动 NoteBook。
   
   针对 1 方案,可如描述中提到的添加 `启动/停止` 按钮,让用户自行控制。
   针对 2 方案,目前已知的条件下,可基于 Jupyter 的 metric 指标利用 Promethues 进行采集,然后 Submarine 
服务会轮询指标情况,针对指定时长(假定为30分钟)没有过执行的 Pod 做资源回收。我在自己的测试环境下针对既有的 Jupyter 
服务做了如下的测试和方案验证:
   
   Jupyter 容器基于 `notebook-controller` 做定制化资源注册,但是 `Service` 缺少 `lables`,暂无法使用 
`Promethues Operator` 的 `ServiceMonitor` 做服务发现,故使用 
`PodMonitor`做验证。在这里,我创建了一个名称为 `test` 的 NoteBook 实例。`PodMonitor` 的描述文件如下:
   
   ```yaml
   apiVersion: monitoring.coreos.com/v1
   kind: PodMonitor
   metadata:
     name: notebook-test
     namespace: submarine
     labels:
       k8s-app-pod: 'true'
   spec: 
     podMetricsEndpoints:
       - path: /notebook/submarine/test/metrics
         port: notebook-port
     namespaceSelector:
       matchNames:
         - submarine
     selector:
       matchLabels:
         statefulset: test
   ```
   
   如图可以看到,Promethus自动发现了这个Pod并开始采集指标。其中,采集的指标内,`` 资源可以作为系统运行时的一个判断。
   同时,我们也可以添加独立的 `Service` 做到相同的效果:
   ```yaml
   kind: Service
   apiVersion: v1
   metadata:
     name: notebook-test-metric
     namespace: submarine
     labels:
       statefulset: test
   spec:
     ports:
       - name: http-test
         protocol: TCP
         port: 8888
         targetPort: 8888
     selector:
       statefulset: test
     type: ClusterIP
   
   
   ```
   ```yaml
   apiVersion: monitoring.coreos.com/v1
   kind: ServiceMonitor
   metadata:
     name: notebook-test
     namespace: submarine
     labels:
       k8s-app-service: 'true'
   spec:
     endpoints:
       - path: /notebook/submarine/test/metrics
         port: http-test
     namespaceSelector:
       matchNames:
         - submarine
     selector:
       matchLabels:
         statefulset: test
   
   ```
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to