# K8s
[K8s](https://hexdocs.pm/k8s/usage.html) - Kubernetes API Client for Elixir
[![Build Status](https://travis-ci.org/coryodaniel/k8s.svg?branch=master)](https://travis-ci.org/coryodaniel/k8s)
[![Coverage Status](https://coveralls.io/repos/github/coryodaniel/k8s/badge.svg?branch=master)](https://coveralls.io/github/coryodaniel/k8s?branch=master)
[![Hex.pm](http://img.shields.io/hexpm/v/k8s.svg?style=flat)](https://hex.pm/packages/k8s)
[![Documentation](https://img.shields.io/badge/documentation-on%20hexdocs-green.svg)](https://hexdocs.pm/k8s/)
![Hex.pm](https://img.shields.io/hexpm/l/k8s.svg?style=flat)
## Features
* A client API for humans đŠđŧđ§đŠđģđŠđŊđŠđžđ§đģđ§đŊđ§đ§đžđ¨đŧđ¨đžđ¨đŋ
* đŽ Kubernetes resources, groups, and CRDs are autodiscovered at boot time. No swagger file to include or override.
* Client supports standard HTTP calls, async batches, wait on status â˛ī¸, and watchers đ
* âī¸ HTTP Request middleware
* Multiple clusters â â â
* đ Multiple authentication credentials
* đ¤ serviceaccount
* token
* đ certificate
* auth-provider
* Pluggable auth providers!
* đ Tested against Kubernetes versions 1.10+ and master
* đ ī¸ CRD support
* đ Integrated with `:telemetry`
* âšī¸ Kubernetes resource and version helper functions
* 𧰠Kube config file parsing
* đī¸ Macro free; fast compile & fast startup
## Installation
The package can be installed by adding `k8s` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:k8s, "~> 0.5"}
]
end
```
## Usage
Check out the [Usage Guide](https://hexdocs.pm/k8s/usage.html) for in-depth examples.
Most functions are also written using doctests.
* [K8s.Client doctests](https://hexdocs.pm/k8s/K8s.Client.html)
* [K8s.Conn doctests](https://hexdocs.pm/k8s/K8s.Conn.html)
* [K8s.Resource doctests](https://hexdocs.pm/k8s/K8s.Resource.html)
* [K8s.Version doctests](https://hexdocs.pm/k8s/K8s.Version.html)
### tl;dr Examples
#### Creating a deployment
```elixir
{: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:
```elixir
{: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:
```elixir
{: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
```elixir
{: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)
```