Skip to content

Commit

Permalink
k8s launcher supports nfs mounting
Browse files Browse the repository at this point in the history
  • Loading branch information
wangjian committed Nov 27, 2024
1 parent ccf8007 commit a3a84bb
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions lazyllm/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def __init__(self, cmd, launcher, *, sync=True):
self.sync = sync
self.deployment_name = f"deployment-{uuid.uuid4().hex[:8]}"
self.namespace = launcher.namespace
self.volume_config = launcher.volume_config
self.volume_configs = launcher.volume_configs
self.gateway_name = launcher.gateway_name
self.deployment_port = 8080
self.host = launcher.http_host
Expand Down Expand Up @@ -233,7 +233,7 @@ def _wrap_cmd(self, cmd):
raise ValueError("Failed to obtain application port.")
return precmd + " " + cmd

def _create_deployment_spec(self, cmd, volume_config=None):
def _create_deployment_spec(self, cmd, volume_configs=None):
container = client.V1Container(
name=self.deployment_name,
image=self.image,
Expand All @@ -242,25 +242,41 @@ def _create_deployment_spec(self, cmd, volume_config=None):
requests=self.resource_config.get("requests", {"cpu": "2", "memory": "16Gi"}),
limits=self.resource_config.get("requests", {"cpu": "2", "memory": "16Gi"})
),
volume_mounts=[] if not volume_config else [
volume_mounts=[] if not volume_configs else [
client.V1VolumeMount(
mount_path=volume_config['mount_path'],
name=volume_config.get("name", "lazyllm-k8s")
)
mount_path=vol_config["mount_path"],
name=vol_config["name"]
) for vol_config in volume_configs
]
)

volumes = []
if volume_config:
volumes.append(
client.V1Volume(
name=volume_config.get("name", "lazyllm-k8s"),
host_path=client.V1HostPathVolumeSource(
path=volume_config["host_path"],
type="Directory"
if volume_configs:
for vol_config in volume_configs:
if "nfs_server" in vol_config and "nfs_path" in vol_config:
volumes.append(
client.V1Volume(
name=vol_config["name"],
nfs=client.V1NFSVolumeSource(
server=vol_config["nfs_server"],
path=vol_config["nfs_path"],
read_only=vol_config.get("read_only", False)
)
)
)
)
)
elif "host_path" in vol_config:
volumes.append(
client.V1Volume(
name=vol_config["name"],
host_path=client.V1HostPathVolumeSource(
path=vol_config["host_path"],
type="Directory"
)
)
)
else:
LOG.error(f"{vol_config} configuration error.")

template = client.V1PodTemplateSpec(
metadata=client.V1ObjectMeta(labels={"app": self.deployment_name}),
spec=client.V1PodSpec(restart_policy="Always", containers=[container], volumes=volumes)
Expand All @@ -280,7 +296,7 @@ def _create_deployment_spec(self, cmd, volume_config=None):
def _create_deployment(self, *, fixed=False):
api_instance = client.AppsV1Api()
cmd = self.get_executable_cmd(fixed=fixed)
deployment = self._create_deployment_spec(cmd.cmd, self.volume_config)
deployment = self._create_deployment_spec(cmd.cmd, self.volume_configs)
try:
api_instance.create_namespaced_deployment(
body=deployment,
Expand Down Expand Up @@ -830,7 +846,7 @@ def status(self):
LOG.error(f"Exception when reading Deployment status: {e}")
return Status.Failed

def __init__(self, kube_config_path=None, volume_config=None, image=None, resource_config=None,
def __init__(self, kube_config_path=None, volume_configs=None, image=None, resource_config=None,
namespace=None, gateway_name=None, host=None, path=None,
svc_type: Literal["LoadBalancer", "NodePort", "ClusterIP"] = None, retry=3,
sync=True, ngpus=None, **kwargs):
Expand All @@ -840,7 +856,7 @@ def __init__(self, kube_config_path=None, volume_config=None, image=None, resour
self.ngpus = ngpus
config_data = self._read_config_file(lazyllm.config['k8s_config_path']) if lazyllm.config['k8s_config_path'] \
else {}
self.volume_config = volume_config if volume_config else config_data.get('volume', {})
self.volume_configs = volume_configs if volume_configs else config_data.get('volume', [])
self.image = image if image else config_data.get('container_image', "lazyllm/lazyllm:k8s_launcher")
self.resource_config = resource_config if resource_config else config_data.get('resource', {})
self.kube_config_path = kube_config_path if kube_config_path \
Expand Down

0 comments on commit a3a84bb

Please sign in to comment.