Crate kube[][src]

Expand description

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


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::api::{Api, ResourceExt, ListParams, PostParams, WatchEvent};
use kube::Client;
use k8s_openapi::api::core::v1::Pod;

async fn main() -> Result<(), kube::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?;

    // Get a strongly typed handle to the Kubernetes API for interacting
    // with pods in the "default" namespace.
    let pods: Api<Pod> = Api::namespaced(client, "default");

    // Create a pod from JSON
    let pod = serde_json::from_value(serde_json::json!({
        "apiVersion": "v1",
        "kind": "Pod",
        "metadata": {
            "name": "my-pod"
        "spec": {
            "containers": [
                    "name": "my-container",
                    "image": "",

    // Create the pod
    let pod = pods.create(&PostParams::default(), &pod).await?;

    // Start a watch call for pods matching our name
    let lp = ListParams::default()
            .fields(&format!("{}", "my-pod"))
    let mut stream =, "0").await?.boxed();

    // Observe the pods phase for 10 seconds
    while let Some(status) = stream.try_next().await? {
        match status {
            WatchEvent::Added(o) => println!("Added {}",,
            WatchEvent::Modified(o) => {
                let s = o.status.as_ref().expect("status exists on pod");
                let phase = s.phase.clone().unwrap_or_default();
                println!("Modified: {} with phase: {}",, phase);
            WatchEvent::Deleted(o) => println!("Deleted {}",,
            WatchEvent::Error(e) => println!("Error {}", e),
            _ => {}




API helpers for structured interaction with the Kubernetes API


A basic API client for interacting with the Kubernetes API


Kubernetes configuration objects from ~/.kube/config or in cluster environment.

Re-exports from kube_core crate.


High-level utilities for runtime API discovery.

errorconfig or client

Error handling in kube



The generic Api abstraction


Client for connecting with a Kubernetes cluster.


Configuration object detailing things like cluster URL, default namespace, root certificates, and timeouts.


A caching client for running API discovery against the Kubernetes API.


Errorconfig or client

Possible errors when working with kube


Extension trait that will be implemented by kube-derive

An accessor trait for a kubernetes Resource.

Helper methods for resources.

Type Definitions

Resultconfig or client

Convient alias for Result<T, Error>

Derive Macros

A custom derive for kubernetes custom resource definitions.