在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):kube-rs/kube-rs开源软件地址(OpenSource Url):https://github.com/kube-rs/kube-rs开源编程语言(OpenSource Language):Rust 98.2%开源软件介绍(OpenSource Introduction):kube-rsA Rust client for Kubernetes in the style of a more generic client-go, a runtime abstraction inspired by controller-runtime, and a derive macro for CRDs inspired by kubebuilder. Hosted by CNCF as a Sandbox Project These crates build upon Kubernetes apimachinery + api concepts to enable generic abstractions. These abstractions allow Rust reinterpretations of reflectors, controllers, and custom resource interfaces, so that you can write applications easily. InstallationSelect a version of [dependencies]
kube = { version = "0.74.0", features = ["runtime", "derive"] }
k8s-openapi = { version = "0.15.0", features = ["v1_24"] } UpgradingPlease check the CHANGELOG when upgrading. All crates herein are versioned and released together to guarantee compatibility before 1.0. UsageSee the examples directory for how to use any of these crates. Official examples:
For real world projects see ADOPTERS. ApiThe use k8s_openapi::api::core::v1::Pod;
let pods: Api<Pod> = Api::default_namespaced(client);
let p = pods.get("blog").await?;
println!("Got blog pod with containers: {:?}", p.spec.unwrap().containers);
let patch = json!({"spec": {
"activeDeadlineSeconds": 5
}});
let pp = PatchParams::apply("kube");
let patched = pods.patch("blog", &pp, &Patch::Apply(patch)).await?;
assert_eq!(patched.spec.active_deadline_seconds, Some(5));
pods.delete("blog", &DeleteParams::default()).await?; See the examples ending in Custom Resource DefinitionsWorking with custom resources uses automatic code-generation via proc_macros in kube-derive. You need to #[derive(CustomResource, Debug, Serialize, Deserialize, Default, Clone, JsonSchema)]
#[kube(group = "kube.rs", version = "v1", kind = "Document", namespaced)]
pub struct DocumentSpec {
title: String,
content: String,
} Then you can use the generated wrapper struct let docs: Api<Document> = Api::default_namespaced(client);
let d = Document::new("guide", DocumentSpec::default());
println!("doc: {:?}", d);
println!("crd: {:?}", serde_yaml::to_string(&Document::crd())); There are a ton of kubebuilder-like instructions that you can annotate with here. See the documentation or the NB: RuntimeThe WatchersA low level streaming interface (similar to informers) that presents let api = Api::<Pod>::default_namespaced(client);
let stream = watcher(api, ListParams::default()).applied_objects(); This now gives a continual stream of events and you do not need to care about the watch having to restart, or connections dropping. while let Some(event) = stream.try_next().await? {
println!("Applied: {}", event.name());
} NB: the plain items in a ReflectorsA let nodes: Api<Node> = Api::all(client);
let lp = ListParams::default().labels("kubernetes.io/arch=amd64");
let (reader, writer) = reflector::store();
let rf = reflector(writer, watcher(nodes, lp)); At this point you can listen to the ControllersA Controller::new(root_kind_api, ListParams::default())
.owns(child_kind_api, ListParams::default())
.run(reconcile, error_policy, context)
.for_each(|res| async move {
match res {
Ok(o) => info!("reconciled {:?}", o),
Err(e) => warn!("reconcile failed: {}", Report::from(e)),
}
})
.await; Here RustlsKube has basic support (with caveats) for rustls as a replacement for the [dependencies]
kube = { version = "0.74.0", default-features = false, features = ["client", "rustls-tls"] }
k8s-openapi = { version = "0.15.0", features = ["v1_24"] } This will pull in musl-libcKube will work with distroless, scratch, and LicenseApache 2.0 licensed. See LICENSE for details. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论