Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[k8s] Add netcat to dependency checks #2712

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/source/reference/kubernetes/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ Submitting SkyPilot tasks to Kubernetes Clusters

Once your cluster administrator has :ref:`setup a Kubernetes cluster <kubernetes-setup>` and provided you with a kubeconfig file:

0. Make sure `kubectl <https://kubernetes.io/docs/tasks/tools/>`_ and ``socat`` are installed on your local machine.
0. Make sure `kubectl <https://kubernetes.io/docs/tasks/tools/>`_, ``socat`` and ``nc`` (netcat) are installed on your local machine.

.. code-block:: console

$ # MacOS
$ brew install kubectl socat
$ brew install kubectl socat netcat

$ # Linux (may have socat already installed)
$ sudo apt-get install kubectl socat
$ sudo apt-get install kubectl socat netcat


1. Place your kubeconfig file at ``~/.kube/config``.
Expand Down
6 changes: 6 additions & 0 deletions sky/templates/kubernetes-port-forward-proxy-command.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ if ! command -v socat > /dev/null; then
exit
fi

# Checks if netcat is installed (may not be present in many docker images)
if ! command -v nc > /dev/null; then
echo "Using 'port-forward' mode to run ssh session on Kubernetes instances requires 'nc' to be installed. Please install 'nc' (netcat)." >&2
exit
fi

# Establishes connection between local port and the ssh jump pod using kube port-forward
# Instead of specifying a port, we let kubectl select a random port.
# This is preferred because of socket re-use issues in kubectl port-forward,
Expand Down
15 changes: 10 additions & 5 deletions sky/utils/kubernetes_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -991,19 +991,24 @@ def fill_ssh_jump_template(ssh_key_secret: str, ssh_jump_image: str,

def check_port_forward_mode_dependencies() -> None:
"""Checks if 'socat' is installed"""
for name, option in [('socat', '-V')]:
# We store the dependency list as a list of lists. Each inner list
# contains the name of the dependency, the command to check if it is
# installed, and the package name to install it.
dependency_list = [['socat', ['socat', '-V'], 'socat'],
['nc', ['nc', '-h'], 'netcat']]
for name, check_cmd, install_cmd in dependency_list:
try:
subprocess.run([name, option],
subprocess.run(check_cmd,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
check=True)
except FileNotFoundError:
except (FileNotFoundError, subprocess.CalledProcessError):
with ux_utils.print_exception_no_traceback():
raise RuntimeError(
f'`{name}` is required to setup Kubernetes cloud with '
f'`{KubernetesNetworkingMode.PORTFORWARD.value}` default '
'networking mode and it is not installed. '
'On Debian/Ubuntu, install it with:\n'
f' $ sudo apt install {name}\n'
f' $ sudo apt install {install_cmd}\n'
f'On MacOS, install it with: \n'
f' $ brew install {name}') from None
f' $ brew install {install_cmd}') from None