https://github.com/mruoss/kubereq
A Kubernetes Client for Elixir based on Req
https://github.com/mruoss/kubereq
api-client elixir kubernetes kubernetes-client
Last synced: about 1 year ago
JSON representation
A Kubernetes Client for Elixir based on Req
- Host: GitHub
- URL: https://github.com/mruoss/kubereq
- Owner: mruoss
- License: mit
- Created: 2024-03-22T17:19:10.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-06-03T21:01:54.000Z (about 1 year ago)
- Last Synced: 2025-06-04T14:44:16.410Z (about 1 year ago)
- Topics: api-client, elixir, kubernetes, kubernetes-client
- Language: Elixir
- Homepage:
- Size: 352 KB
- Stars: 11
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
- fucking-awesome-elixir - Kubereq - Kubernetes Client for Elixir based on Req. (Cloud Infrastructure and Management)
- awesome-elixir - Kubereq - Kubernetes Client for Elixir based on Req. (Cloud Infrastructure and Management)
README
# Kubereq
Used by [`kubegen`](https://github.com/mruoss/kubegen) to build Resource based
Kubernetes API clients using Req with `kubereq`.
[](https://hex.pm/packages/kubereq)
[](https://github.com/mruoss/kubereq/commits/main)
[](https://hexdocs.pm/kubereq/)
[](https://hex.pm/packages/kubereq)
[](https://github.com/mruoss/kubereq/blob/main/LICENSE.md)
While this library can be used directly, it is easier to let
[`kubegen`](https://github.com/mruoss/kubegen) generate the API client modules
for you. The resulting clients are then using `kubereq` to get the prepared
`Req.Request` struct and make the requests to the Kubernetes API Server.
## Installation
The package can be installed by adding `kubereq` to your list of dependencies in
`mix.exs`:
```elixir
def deps do
[
{:kubereq, "~> 0.4.0"}
]
end
```
The docs can be found at .
## Usage
This library can be used with plain `Req` but the functions in this module
provide an easier API to people used to `kubectl` and friends.
### Kubereq API
While you can use this library with plain `Req` functions (see below), it is
easier to prepare a `Req` request for a specific resource and then use the
functions defined in the `Kubereq` module.
```ex
sa_req = Req.new() |> Kubereq.attach(api_version: "v1", kind: "ServiceAccount")
Kubereq.get(sa_req, "my-namespace", "default")
Kubereq.list(sa_req, "my-namespace")
```
Or use the functions right away, defining the resource through options:
```ex
req = Req.new() |> Kubereq.attach()
Kubereq.get(req, "my-namespace", "default", api_version: "v1", kind: "ServiceAccount")
# get the "status" subresource of the default namespace
Kubereq.get(req, "my-namespace", api_version: "v1", kind: "Namespace", subresource: "status")
```
For resources defined by Kubernetes, the `api_version` can be omitted:
```ex
Req.new()
|> Kubereq.attach(kind: "Namespace")
|> Kubereq.get("my-namespace")
```
### Plain Req
Inestead of using the function in `Kubereq`, you can use
`Kubereq.Kubeconfig.Default` to create connection to the cluster and then use
plain `Req.request()` to make the request.
```ex
req = Req.new() |> Kubereq.attach()
Req.request!(req,
api_version: "v1",
kind: "ServiceAccount",
operation: :get,
path_params: [namespace: "default", name: "default"]
)
```
You can pass your own Kubeconfigloader pipeline when attaching:
```ex
req = Req.new() |> Kubereq.attach(kubeconfig: {Kubereq.Kubeconfig.File, path: "/path/to/kubeconfig.yaml"})
Req.request!(req,
api_version: "v1",
kind: "ServiceAccount",
operation: :get,
path_params: [namespace: "default", name: "default"]
)
```
Prepare a `Req` struct for a specific resource:
```ex
sa_req = Req.new() |> Kubereq.attach(api_version: "v1", kind: "ServiceAccount")
Req.request!(sa_req, operation: :get, path_params: [namespace: "default", name: "default"])
Req.request!(sa_req, operation: :list, path_params: [namespace: "default"])
```