Struct kube::Client [−][src]
pub struct Client { /* fields omitted */ }
client
only.Expand description
Client for connecting with a Kubernetes cluster.
The easiest way to instantiate the client is either by
inferring the configuration from the environment using
Client::try_default
or with an existing Config
using Client::try_from
.
Implementations
pub fn new<S, B, T>(service: S, default_namespace: T) -> Client where
S: 'static + Service<Request<Body>, Response = Response<B>> + Send,
B: 'static + Body<Data = Bytes> + Send,
T: Into<String>,
<S as Service<Request<Body>>>::Future: 'static,
<S as Service<Request<Body>>>::Future: Send,
<S as Service<Request<Body>>>::Error: Into<Box<dyn Error + Send + Sync + 'static, Global>>,
<B as Body>::Error: 'static,
<B as Body>::Error: Error,
<B as Body>::Error: Send,
<B as Body>::Error: Sync,
pub fn new<S, B, T>(service: S, default_namespace: T) -> Client where
S: 'static + Service<Request<Body>, Response = Response<B>> + Send,
B: 'static + Body<Data = Bytes> + Send,
T: Into<String>,
<S as Service<Request<Body>>>::Future: 'static,
<S as Service<Request<Body>>>::Future: Send,
<S as Service<Request<Body>>>::Error: Into<Box<dyn Error + Send + Sync + 'static, Global>>,
<B as Body>::Error: 'static,
<B as Body>::Error: Error,
<B as Body>::Error: Send,
<B as Body>::Error: Sync,
Create a Client
using a custom Service
stack.
ConfigExt
provides extensions for
building a custom stack.
To create with the default stack with a Config
, use
Client::try_from
.
To create with the default stack with an inferred Config
, use
Client::try_default
.
Example
use kube::{client::ConfigExt, Client, Config};
use tower::ServiceBuilder;
let config = Config::infer().await?;
let service = ServiceBuilder::new()
.layer(config.base_uri_layer())
.option_layer(config.auth_layer()?)
.service(hyper::Client::new());
let client = Client::new(service, config.default_namespace);
Create and initialize a Client
using the inferred
configuration.
Will use Config::infer
to try in-cluster enironment
variables first, then fallback to the local kubeconfig.
Will fail if neither configuration could be loaded.
If you already have a Config
then use Client::try_from
instead.
pub async fn connect(
&'_ self,
request: Request<Vec<u8, Global>>
) -> Result<WebSocketStream<Upgraded>, Error>
This is supported on crate feature ws
only.
pub async fn connect(
&'_ self,
request: Request<Vec<u8, Global>>
) -> Result<WebSocketStream<Upgraded>, Error>
ws
only.Make WebSocket connection.
Perform a raw HTTP request against the API and deserialize the response as JSON to some known type.
Perform a raw HTTP request against the API and get back the response as a string
Perform a raw HTTP request against the API and get back the response as a stream of bytes
Perform a raw HTTP request against the API and get back either an object
deserialized as JSON or a Status
Object.
pub async fn request_events<T>(
&'_ self,
request: Request<Vec<u8, Global>>
) -> Result<impl TryStream, Error> where
T: Clone + DeserializeOwned,
pub async fn request_events<T>(
&'_ self,
request: Request<Vec<u8, Global>>
) -> Result<impl TryStream, Error> where
T: Clone + DeserializeOwned,
Perform a raw request and get back a stream of WatchEvent
objects
Low level discovery methods using k8s_openapi
types.
Consider using the discovery
module for
easier-to-use variants of this functionality.
The following methods might be deprecated to avoid confusion between similarly named types within discovery
.
Returns apiserver version.
Lists api groups that apiserver serves.
pub async fn list_api_group_resources(
&'_ self,
apiversion: &'_ str
) -> Result<APIResourceList, Error>
pub async fn list_api_group_resources(
&'_ self,
apiversion: &'_ str
) -> Result<APIResourceList, Error>
Lists resources served in given API group.
Example usage:
let apigroups = client.list_api_groups().await?;
for g in apigroups.groups {
let ver = g
.preferred_version
.as_ref()
.or_else(|| g.versions.first())
.expect("preferred or versions exists");
let apis = client.list_api_group_resources(&ver.group_version).await?;
dbg!(apis);
}
Lists versions of core
a.k.a. ""
legacy API group.
pub async fn list_core_api_resources(
&'_ self,
version: &'_ str
) -> Result<APIResourceList, Error>
pub async fn list_core_api_resources(
&'_ self,
version: &'_ str
) -> Result<APIResourceList, Error>
Lists resources served in particular core
group version.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Client
impl !UnwindSafe for Client
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more