Skip to content

Commit

Permalink
make ssh services optional
Browse files Browse the repository at this point in the history
  • Loading branch information
romilbhardwaj committed Apr 17, 2024
1 parent 750d4d4 commit 87d4d25
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sky/clouds/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ def make_deploy_resources_variables(
kubernetes_utils.get_gpu_label_key_value(acc_type)

port_mode = network_utils.get_port_mode(None)
networking_mode = network_utils.get_networking_mode(None)

remote_identity = skypilot_config.get_nested(
('kubernetes', 'remote_identity'), schemas.REMOTE_IDENTITY_DEFAULT)
Expand Down Expand Up @@ -289,6 +290,7 @@ def make_deploy_resources_variables(
'k8s_namespace':
kubernetes_utils.get_current_kube_config_context_namespace(),
'k8s_port_mode': port_mode.value,
'k8s_networking_mode': networking_mode.value,
'k8s_ssh_key_secret_name': self.SKY_SSH_KEY_SECRET_NAME,
'k8s_acc_label_key': k8s_acc_label_key,
'k8s_acc_label_value': k8s_acc_label_value,
Expand Down
17 changes: 17 additions & 0 deletions sky/provision/kubernetes/network_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ def get_port_mode(
return port_mode


def get_networking_mode(mode_str: Optional[str] = None) -> kubernetes_enums.KubernetesNetworkingMode:
"""Get the networking mode from the provider config."""
mode_str = mode_str or skypilot_config.get_nested(
('kubernetes', 'networking_mode'),
kubernetes_enums.KubernetesNetworkingMode.PORTFORWARD.value)
try:
networking_mode = kubernetes_enums.KubernetesNetworkingMode(mode_str)
except ValueError as e:
with ux_utils.print_exception_no_traceback():
raise ValueError(str(e)
+ ' Cluster was setup with invalid networking mode.'
+ 'Please check the networking_mode in provider config.') \
from None

return networking_mode


def fill_loadbalancer_template(namespace: str, service_name: str,
ports: List[int], selector_key: str,
selector_value: str) -> Dict:
Expand Down
8 changes: 8 additions & 0 deletions sky/templates/kubernetes-ray.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,11 @@ provider:
name: skypilot-service-account-cluster-role
apiGroup: rbac.authorization.k8s.io

{% if k8s_networking_mode == "nodeport" or num_nodes > 1 %}
services:
{% if k8s_networking_mode == "nodeport" %}
# Service to expose the head node pod's SSH port.
# Required only when using nodeport for accessing ssh.
- apiVersion: v1
kind: Service
metadata:
Expand All @@ -171,7 +174,10 @@ provider:
- protocol: TCP
port: 22
targetPort: 22
{% endif %}
{% if num_nodes > 1 %}
# Service that maps to the head node of the Ray cluster.
# Required only in multi-node settings.
- apiVersion: v1
kind: Service
metadata:
Expand All @@ -195,6 +201,8 @@ provider:
protocol: TCP
port: 8265
targetPort: 8265
{% endif %}
{% endif %}

# Specify the pod type for the ray head node (as configured below).
head_node_type: ray_head_default
Expand Down

0 comments on commit 87d4d25

Please sign in to comment.