Packages
k8s
0.5.1
2.8.0
2.7.0
2.6.2
2.6.1
2.6.0
2.5.0
2.4.2
2.4.1
2.4.0
2.3.0
2.2.0
2.1.1
2.1.0
2.0.3
2.0.2
2.0.1
2.0.0
2.0.0-rc.6
2.0.0-rc.5
2.0.0-rc.4
2.0.0-rc.3
2.0.0-rc.2
2.0.0-rc.1
2.0.0-rc.0
1.2.1
1.2.0
1.1.10
1.1.9
1.1.8
1.1.7
1.1.6
1.1.5
1.1.4
1.1.3
1.1.2
1.1.1
1.1.0
1.0.0
1.0.0-rc1
0.5.2
0.5.1
0.5.0
0.5.0-rc.2
0.5.0-rc.1
0.4.0
0.3.2
0.3.1
0.3.0
0.2.13
0.2.12
0.2.11
0.2.10
0.2.9
0.2.8
0.2.7
retired
0.2.6
0.2.5
0.2.4
0.2.3
0.2.2
0.2.1
0.2.0
0.1.3
Kubernetes API Client for Elixir
Current section
Files
Jump to
Current section
Files
README.md
# K8s
[K8s](https://hexdocs.pm/k8s/usage.html) - Kubernetes API Client for Elixir
[](https://travis-ci.org/coryodaniel/k8s)
[](https://coveralls.io/github/coryodaniel/k8s?branch=master)
[](https://hex.pm/packages/k8s)
[](https://hexdocs.pm/k8s/)

## 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)
If you are interested in building Kubernetes Operators or Schedulers, check out [Bonny](https://github.com/coryodaniel/bonny).
### tl;dr Examples
#### Configure a cluster
There are many ways to configure cluster connections. Check out the [guide](https://hexdocs.pm/k8s/connections.html) for additional options.
In `config.exs`:
```elixir
config :k8s,
clusters: %{
prod_us_east1: %{ # <- this can be any name, used to load connections later
# Path to kube config
conn: "~/.kube/config",
# By default current context will be used, you can change the user or cluster
conn_opts: [user: "some-user", cluster: "prod-cluster"]
}
}
```
#### 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)
```