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<(), kube_client::Error> {
let client = Client::try_default().await?;
let pods: Api<Pod> = Api::default_namespaced(client);
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",
},
],
}
}))?;
let params = PatchParams::apply("myapp");
let result = pods.patch("my-pod", ¶ms, &Patch::Apply(&patch)).await?;
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