K8s

K8s - Kubernetes API Client for Elixir

Build StatusCoverage StatusHex.pmDocumentationHex.pm

Features

Installation

The package can be installed by adding k8s to your list of dependencies in mix.exs:

def deps do
  [
    {:k8s, "~> 0.5"}
  ]
end

Usage

Check out the Usage Guide for in-depth examples.

Most functions are also written using doctests.

tl;dr Examples

Creating a deployment

{:ok, conn} = K8s.Conn.lookup(:prod_us_east1)

opts = [namespace: "default", name: "nginx", image: "nginx:nginx:1.7.9"]
{:ok, resource} = K8s.Resource.from_file("priv/deployment.yaml", opts)

operation = K8s.Client.create(resource)
{:ok, deployment} = K8s.Client.run(operation, conn)

Listing deployments

In a namespace:

{:ok, conn} = K8s.Conn.lookup(:prod_us_east1)

operation = K8s.Client.list("apps/v1", "Deployment", namespace: "prod")
{:ok, deployments} = K8s.Client.run(operation, conn)

Across all namespaces:

{:ok, conn} = K8s.Conn.lookup(:prod_us_east1)

operation = K8s.Client.list("apps/v1", "Deployment", namespace: :all)
{:ok, deployments} = K8s.Client.run(operation, conn)

Getting a deployment

{:ok, conn} = K8s.Conn.lookup(:prod_us_east1)

operation = K8s.Client.get("apps/v1", :deployment, [namespace: "default", name: "nginx-deployment"])
{:ok, deployment} = K8s.Client.run(operation, conn)