K8s - Kubernetes API Client for Elixir
- 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
The package can be installed by adding k8s
to your list of dependencies in mix.exs
:
def deps do
[
{:k8s, "~> 0.5"}
]
end
Check out the Usage Guide for in-depth examples.
Most functions are also written using doctests.
If you are interested in building Kubernetes Operators or Schedulers, check out Bonny.
There are many ways to configure cluster connections. Check out the guide for additional options.
In config.exs
:
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"]
}
}
{: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)
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)
{: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)