mirror of
https://github.com/tencentmusic/cube-studio.git
synced 2024-11-21 01:16:33 +08:00
支持mlops+边缘计算
This commit is contained in:
parent
01d5fb603e
commit
8cfb7f9f65
14
myapp/cli.py
14
myapp/cli.py
@ -1304,7 +1304,7 @@ def init():
|
||||
|
||||
|
||||
# 添加demo 服务
|
||||
def create_service(project_name,service_name,service_describe,image_name,command,env,resource_mem='2G',resource_cpu='2',port='80'):
|
||||
def create_service(project_name,service_name,service_describe,image_name,command,env,resource_mem='2G',resource_cpu='2',ports='80'):
|
||||
service = db.session.query(Service).filter_by(name=service_name).first()
|
||||
project = db.session.query(Project).filter_by(name=project_name).filter_by(type='org').first()
|
||||
if service is None and project:
|
||||
@ -1318,7 +1318,7 @@ def init():
|
||||
service.images=image_name
|
||||
service.command = command
|
||||
service.env='\n'.join([x.strip() for x in env.split('\n') if x.split()])
|
||||
service.port = port
|
||||
service.ports = ports
|
||||
db.session.add(service)
|
||||
db.session.commit()
|
||||
except Exception as e:
|
||||
@ -1338,7 +1338,7 @@ def init():
|
||||
PMA_USER=root
|
||||
PMA_PASSWORD=admin
|
||||
''',
|
||||
port='80'
|
||||
ports='80'
|
||||
)
|
||||
|
||||
# 部署redis-ui
|
||||
@ -1354,7 +1354,7 @@ def init():
|
||||
REDIS_PORT=6379
|
||||
REDIS_PASSWORD=admin
|
||||
''',
|
||||
port='7843'
|
||||
ports='7843'
|
||||
)
|
||||
|
||||
# 部署mongo ui
|
||||
@ -1377,7 +1377,7 @@ def init():
|
||||
VCAP_APP_PORT=8081
|
||||
ME_CONFIG_OPTIONS_EDITORTHEME=ambiance
|
||||
''',
|
||||
port='8081'
|
||||
ports='8081'
|
||||
)
|
||||
|
||||
|
||||
@ -1391,7 +1391,7 @@ def init():
|
||||
env='''
|
||||
NEO4J_AUTH=neo4j/admin
|
||||
''',
|
||||
port='7474,7687'
|
||||
ports='7474,7687'
|
||||
)
|
||||
|
||||
# 部署jaeger链路追踪
|
||||
@ -1402,7 +1402,7 @@ def init():
|
||||
image_name='jaegertracing/all-in-one:1.29',
|
||||
command='',
|
||||
env='',
|
||||
port='5775,16686'
|
||||
ports='5775,16686'
|
||||
)
|
||||
|
||||
|
||||
|
@ -69,6 +69,13 @@ class Notebook(Model,AuditMixinNullable,MyappModelBase):
|
||||
host = "http://"+JUPYTER_DOMAIN
|
||||
else:
|
||||
host = "http://"+request.host # 使用当前域名打开
|
||||
|
||||
# 对于有边缘节点,直接使用边缘集群的代理ip
|
||||
SERVICE_EXTERNAL_IP = json.loads(self.project.expand).get('SERVICE_EXTERNAL_IP',None) if self.project.expand else None
|
||||
if SERVICE_EXTERNAL_IP:
|
||||
service_ports = 10000 + 10 * self.id
|
||||
host = "http://%s:%s"%(SERVICE_EXTERNAL_IP,str(service_ports))
|
||||
url='/#/mnt/%s'%self.created_by.username
|
||||
return Markup(f'<a target=_blank href="{host}{url}">{self.name}</a>')
|
||||
|
||||
@property
|
||||
|
@ -110,10 +110,20 @@ class Service(Model,AuditMixinNullable,MyappModelBase,service_common):
|
||||
|
||||
@property
|
||||
def ip(self):
|
||||
|
||||
# 优先使用项目组配置的代理ip
|
||||
SERVICE_EXTERNAL_IP = json.loads(self.project.expand).get('SERVICE_EXTERNAL_IP',None) if self.project.expand else None
|
||||
if SERVICE_EXTERNAL_IP:
|
||||
host = SERVICE_EXTERNAL_IP+":"+str(30000+10*self.id)
|
||||
return Markup(f'<a target=_blank href="http://{host}/">{host}</a>')
|
||||
|
||||
# 再使用全局配置代理ip
|
||||
SERVICE_EXTERNAL_IP = conf.get('SERVICE_EXTERNAL_IP',[])
|
||||
|
||||
if SERVICE_EXTERNAL_IP:
|
||||
SERVICE_EXTERNAL_IP = SERVICE_EXTERNAL_IP[0]
|
||||
return SERVICE_EXTERNAL_IP+":"+str(30000+10*self.id)
|
||||
host = SERVICE_EXTERNAL_IP + ":" + str(30000 + 10 * self.id)
|
||||
return Markup(f'<a target=_blank href="http://{host}/">{host}</a>')
|
||||
else:
|
||||
return "未开通"
|
||||
|
||||
|
@ -292,7 +292,7 @@ class Notebook_ModelView_Base():
|
||||
def reset_theia(self, notebook):
|
||||
from myapp.utils.py.py_k8s import K8s
|
||||
|
||||
k8s = K8s(notebook.cluster['KUBECONFIG'])
|
||||
k8s_client = K8s(notebook.cluster['KUBECONFIG'])
|
||||
namespace = conf.get('NOTEBOOK_NAMESPACE')
|
||||
port=3000
|
||||
|
||||
@ -335,7 +335,7 @@ class Notebook_ModelView_Base():
|
||||
image_secrets.append(hubsecret[0])
|
||||
|
||||
|
||||
k8s.create_debug_pod(
|
||||
k8s_client.create_debug_pod(
|
||||
namespace=namespace,
|
||||
name=notebook.name,
|
||||
labels={"app":notebook.name,'user':notebook.created_by.username},
|
||||
@ -358,7 +358,7 @@ class Notebook_ModelView_Base():
|
||||
accounts=conf.get('JUPYTER_ACCOUNTS'),
|
||||
username=notebook.created_by.username
|
||||
)
|
||||
k8s.create_service(
|
||||
k8s_client.create_service(
|
||||
namespace=namespace,
|
||||
name=notebook.name,
|
||||
username=notebook.created_by.username,
|
||||
@ -366,9 +366,9 @@ class Notebook_ModelView_Base():
|
||||
|
||||
crd_info = conf.get('CRD_INFO', {}).get('virtualservice', {})
|
||||
crd_name = "notebook-jupyter-%s"%notebook.name.replace('_', '-') # notebook.name.replace('_', '-')
|
||||
vs_obj = k8s.get_one_crd(group=crd_info['group'], version=crd_info['version'], plural=crd_info['plural'],namespace=namespace, name=crd_name)
|
||||
vs_obj = k8s_client.get_one_crd(group=crd_info['group'], version=crd_info['version'], plural=crd_info['plural'],namespace=namespace, name=crd_name)
|
||||
if vs_obj:
|
||||
k8s.delete_crd(group=crd_info['group'], version=crd_info['version'], plural=crd_info['plural'],namespace=namespace, name=crd_name)
|
||||
k8s_client.delete_crd(group=crd_info['group'], version=crd_info['version'], plural=crd_info['plural'],namespace=namespace, name=crd_name)
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
@ -420,7 +420,27 @@ class Notebook_ModelView_Base():
|
||||
}
|
||||
|
||||
# print(crd_json)
|
||||
crd = k8s.create_crd(group=crd_info['group'], version=crd_info['version'], plural=crd_info['plural'],namespace=namespace, body=crd_json)
|
||||
crd = k8s_client.create_crd(group=crd_info['group'], version=crd_info['version'], plural=crd_info['plural'],namespace=namespace, body=crd_json)
|
||||
|
||||
# 创建EXTERNAL_IP的服务
|
||||
SERVICE_EXTERNAL_IP = conf.get('SERVICE_EXTERNAL_IP', None)
|
||||
if not SERVICE_EXTERNAL_IP and notebook.project.expand:
|
||||
SERVICE_EXTERNAL_IP = json.loads(notebook.project.expand).get('SERVICE_EXTERNAL_IP', SERVICE_EXTERNAL_IP)
|
||||
if type(SERVICE_EXTERNAL_IP)==str:
|
||||
SERVICE_EXTERNAL_IP = [SERVICE_EXTERNAL_IP]
|
||||
|
||||
if SERVICE_EXTERNAL_IP:
|
||||
service_ports = [[10000 + 10 * notebook.id + index, port] for index, port in enumerate([port])]
|
||||
service_external_name = (notebook.name + "-external").lower()[:60].strip('-')
|
||||
k8s_client.create_service(
|
||||
namespace=namespace,
|
||||
name=service_external_name,
|
||||
username=notebook.created_by.username,
|
||||
ports=service_ports,
|
||||
selector={"app": notebook.name, 'user': notebook.created_by.username},
|
||||
externalIPs=SERVICE_EXTERNAL_IP
|
||||
)
|
||||
|
||||
return crd
|
||||
|
||||
# @event_logger.log_this
|
||||
|
@ -231,7 +231,13 @@ class Service_ModelView(MyappModelView):
|
||||
)
|
||||
|
||||
# 以ip形式访问的话,使用的代理ip。不然不好处理机器服务化机器扩容和缩容时ip变化
|
||||
SERVICE_EXTERNAL_IP = conf.get('SERVICE_EXTERNAL_IP',None)
|
||||
# 创建EXTERNAL_IP的服务
|
||||
SERVICE_EXTERNAL_IP = conf.get('SERVICE_EXTERNAL_IP', None)
|
||||
if not SERVICE_EXTERNAL_IP and service.project.expand:
|
||||
SERVICE_EXTERNAL_IP = json.loads(service.project.expand).get('SERVICE_EXTERNAL_IP', SERVICE_EXTERNAL_IP)
|
||||
if type(SERVICE_EXTERNAL_IP)==str:
|
||||
SERVICE_EXTERNAL_IP = [SERVICE_EXTERNAL_IP]
|
||||
|
||||
if SERVICE_EXTERNAL_IP:
|
||||
service_ports = [[30000+10*service.id+index,port] for index,port in enumerate(ports)]
|
||||
service_external_name = (service.name + "-external").lower()[:60].strip('-')
|
||||
@ -241,7 +247,7 @@ class Service_ModelView(MyappModelView):
|
||||
username=service.created_by.username,
|
||||
ports=service_ports,
|
||||
selector={"app": service.name, 'user': service.created_by.username},
|
||||
externalIPs=conf.get('SERVICE_EXTERNAL_IP',None)
|
||||
externalIPs=SERVICE_EXTERNAL_IP
|
||||
)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user