Important
This repository is archived. The smart cell is now integrated in the "Connect to Pod" smart cell of kino_k8s. Check it out!
A Livebook Kino to run a Terminal for Kubernetes Pods.
This Kino uses the Elixir library k8s to open a connection to a pod and Xterm.js to render a terminal in your livebook. Refer to these projects for inside information.
kino_k8s_term.mp4
This Kino is currently not published on hex.pm. To use it, install it from git:
Mix.install([
{:kino_k8s_term, git: "https://github.com/mruoss/kino_k8s_term.git", branch: "main"}
])
You can either use the Smart Cell or call KinoK8sTerm.open/4
manually.
conn
- a%K8s.Conn{}
struct that can be optained by callingK8s.Conn.from_file/2
namespace
- The namespace your pod runs inpod
- The name of your pod
container
- If your pod runs multiple containers, define the container you want to connect to.command
- optional. The shell that is executed once connected. Defaults to/bin/sh
.
{:ok, conn} = K8s.Conn.from_file("~/.kube/config", context: "some_local_cluster")
# For local clusters, you might want to skip TLS verification
conn = struct!(conn, insecure_skip_tls_verify: true)
namespace = "default"
pod = "nginx-deployment-6595874d85-5kdf4"
container = "nginx"
command = "/bin/bash"
KinoK8sTerm.open(conn, namespace, pod, container: container, command: command)
This Kino comes with a smart cell, too. Open this README in Livebook to see it in action.
IO.puts("Connection could not be established.
Please configure the connection to the pod and reevaluate the cell.")
:no_conn
Note that the user defined in the conn
object needs permissions to the pods/exec
resource in your cluster. If this is not given, the terminal can't be opened.
Use this Kino for local clusters only. Or protect your livebook well from unwanted access.