14 releases (breaking)

Uses new Rust 2021

new 0.72.0 May 13, 2022
0.70.0 Mar 20, 2022
0.65.0 Dec 10, 2021
0.64.0 Nov 16, 2021

#28 in HTTP client

Download history 10034/week @ 2022-01-27 13528/week @ 2022-02-03 11215/week @ 2022-02-10 11431/week @ 2022-02-17 9798/week @ 2022-02-24 10024/week @ 2022-03-03 10952/week @ 2022-03-10 12733/week @ 2022-03-17 12366/week @ 2022-03-24 18785/week @ 2022-03-31 23612/week @ 2022-04-07 21543/week @ 2022-04-14 20162/week @ 2022-04-21 15983/week @ 2022-04-28 16214/week @ 2022-05-05 13686/week @ 2022-05-12

70,814 downloads per month
Used in 23 crates (3 directly)

Apache-2.0

420KB
7.5K SLoC

kube-client

The rust counterpart to kubernetes/client-go. Contains the IO layer plus the core Api layer, and also as well as config parsing.

Usage

This crate, and all its features, are re-exported from the facade-crate kube.

Docs

See the kube-client API Docs

Development

Help very welcome! To help out on this crate check out these labels:


lib.rs:

Crate for interacting with the Kubernetes API

This crate includes the tools for manipulating Kubernetes resources as well as keeping track of those resources as they change over time

Example

The following example will create a Pod and then watch for it to become available using a manual [Api::watch] call.

use futures::{StreamExt, TryStreamExt};
use kube_client::api::{Api, ResourceExt, ListParams, PatchParams, Patch};
use kube_client::Client;
use k8s_openapi::api::core::v1::Pod;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Read the environment to find config for kube client.
    // Note that this tries an in-cluster configuration first,
    // then falls back on a kubeconfig file.
    let client = Client::try_default().await?;

    // Interact with pods in the configured namespace with the typed interface from k8s-openapi
    let pods: Api<Pod> = Api::default_namespaced(client);

    // Create a Pod (cheating here with json, but it has to validate against the type):
    let patch: Pod = serde_json::from_value(serde_json::json!({
        "apiVersion": "v1",
        "kind": "Pod",
        "metadata": {
            "name": "my-pod"
        },
        "spec": {
            "containers": [
                {
                    "name": "my-container",
                    "image": "myregistry.azurecr.io/hello-world:v1",
                },
            ],
        }
    }))?;

    // Apply the Pod via server-side apply
    let params = PatchParams::apply("myapp");
    let result = pods.patch("my-pod", &params, &Patch::Apply(&patch)).await?;

    // List pods in the configured namespace
    for p in pods.list(&ListParams::default()).await? {
        println!("found pod {}", p.name());
    }

    Ok(())
}

For more details, see:

  • Client for the extensible Kubernetes client
  • Config for the Kubernetes config abstraction
  • Api for the generic api methods available on Kubernetes resources
  • k8s-openapi for how to create typed kubernetes objects directly

Dependencies

~76MB
~1M SLoC