Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Kino_K8s Development

dev.livemd

Kino_K8s Development

# Mix.install([{:kino_k8s, github: "mruoss/kino_k8s"}])
Mix.install([{:kino_k8s, path: "~/src/community/kino_k8s"}])

Section

{:ok, conn} =
  K8s.Conn.from_file("~/.kube/config",
    context: "kind-kino-k8s",
    insecure_skip_tls_verify: true
  )

conn
connect_to_pod = fn terminal_kino_pid ->
  {:ok, send_to_websocket} =
    K8s.Client.connect("v1", "pods/exec", [namespace: "kino-k8s", name: "busybox"],
      container: "busybox",
      command: "/bin/sh",
      tty: true
    )
    |> K8s.Client.put_conn(conn)
    |> K8s.Client.stream_to(terminal_kino_pid)

  send_to_websocket
end

KinoK8s.KinoTerminal.open(connect_to_pod)
import YamlElixir.Sigil

{:ok, applied_resource} =
  ~y"""
  apiVersion: v1
  kind: Pod
  metadata:
    name: busybox
    namespace: kino-k8s
  spec:
    containers:
    - image: busybox
      command:
        - sleep
        - "3600"
      imagePullPolicy: IfNotPresent
      name: busybox
    restartPolicy: Always
  """
  |> K8s.Client.apply()
  |> K8s.Client.put_conn(conn)
  |> K8s.Client.run()

Kino.Markdown.new("#### Applied Resource:

```yaml
#{Ymlr.document!(applied_resource)}
```
")