Use Livebook to open this notebook and explore new ideas.
It is easy to get started, on your machine or the cloud.
# ⚠️ ARCHIVED ⚠️ KinoK8sTerm
> [!IMPORTANT]
> This repository is archived. The smart cell is now integrated in the
> "Connect to Pod" smart cell of [kino_k8s](https://github.com/mruoss/kino_k8s).
> Check it out!
A Livebook Kino to run a Terminal for Kubernetes Pods.
## Section
[](https://livebook.dev/run?url=https%3A%2F%2Fgithub.com%2Fmruoss%2Fkino_k8s_term%2Fblob%2Fmain%2FREADME.livemd)
## About
This Kino uses the Elixir library [k8s](https://github.com/coryodaniel/k8s) to open a connection to a pod and [Xterm.js](http://xtermjs.org/) to render a terminal in your livebook. Refer to these projects for inside information.
https://user-images.githubusercontent.com/695307/208457804-614b5a82-9108-4281-b711-df8ac4040be3.mp4
## Installation
This Kino is currently not published on hex.pm. To use it, install it from git:
```elixir
Mix.install([
{:kino_k8s_term, git: "https://github.com/mruoss/kino_k8s_term.git", branch: "main"}
])
```
## Usage
You can either use the Smart Cell or call `KinoK8sTerm.open/4` manually.
### Arguments
- `conn` - a `%K8s.Conn{}` struct that can be optained by calling `K8s.Conn.from_file/2`
- `namespace` - The namespace your pod runs in
- `pod` - The name of your pod
### Options
- `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`.
```elixir
{: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)
```
## Smart Cell
This Kino comes with a smart cell, too. [Open this README in Livebook](https://livebook.dev/run?url=https%3A%2F%2Fgithub.com%2Fmruoss%2Fkino_k8s_term%2Fblob%2Fmain%2FREADME.livemd) to see it in action.
<!-- livebook:{"attrs":{},"chunks":null,"kind":"Elixir.KinoK8sTerm.SmartCell","livebook_object":"smart_cell"} -->
```elixir
IO.puts("Connection could not be established.
Please configure the connection to the pod and reevaluate the cell.")
:no_conn
```
## Security
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.
See source