-
Hi. Is it possible to create a client without a config I develop a micro-service that interacts directly with k8s REST API. It goes well with Currently, it looks like this: let client = Client::new();
let resp = client
.get("http://10.10.10.10:8081/api/v1") // k8s REST API URL
.basic_auth(username, Some(password))
.send()
.await; In cURL, it looks like this curl --request GET \
--url 'http://10.10.10.10:8081/api/v1/namespaces/disney/pods/?labelSelector=pocahontas' \
--header 'Authorization: Basic secret' Is it possible to pass only For additional perspective, I can avoid using the config file for the AWS S3 client. let secret_key = "secret";
let access_key = "key";
let url = "https://storage.example.net";
let cred = aws_sdk_s3::Credentials::new(access_key, secret_key, None, None, "custom"); Thanks in advance! ❤️ |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
You can create a custom If your API gives you a kubeconfig then you can also use |
Beta Was this translation helpful? Give feedback.
-
For searcher who arrived here. First, you need the kubeconfig. Writing curl -s -X POST -H "Authorization: Bearer <your token>" https://rancher.app.example.net/v3/clusters/<your cluster>?action=generateKubeconfig | jq -r ".config" Put the configuration in Second, you can use the custom location of the config file using: let kube_config = Kubeconfig::read_from("/home/user/playground/rust/src/kube.cfg").unwrap();
let kube_config_options = KubeConfigOptions {
context: None,
cluster: None,
user: None,
};
let config = kube::Config::from_custom_kubeconfig(kube_config, &kube_config_options).await.unwrap();
let client = Client::try_from(config).unwrap(); Finally, if you don't want to read from a file. Just pretty print the value of let kube_config = Kubeconfig {
preferences: None,
clusters: [NamedCluster {
name: "local".to_string(),
cluster: Cluster {
server: "https://rancher.app.example.net/v3/clusters/local"
.to_string(),
insecure_skip_tls_verify: None,
certificate_authority: None,
certificate_authority_data: None,
proxy_url: None,
extensions: None,
},
}]
.to_vec(),
auth_infos: [NamedAuthInfo {
name: "local".to_string(),
auth_info: AuthInfo {
username: None,
password: None,
token: Some(Secret::new("kubeconfig-user-secret:secret".to_string())),
token_file: None,
client_certificate: None,
client_certificate_data: None,
client_key: None,
client_key_data: None,
impersonate: None,
impersonate_groups: None,
auth_provider: None,
exec: None,
},
}]
.to_vec(),
contexts: [NamedContext {
name: "local".to_string(),
context: Context {
cluster: "local".to_string(),
user: "local".to_string(),
namespace: None,
extensions: None,
},
}]
.to_vec(),
current_context: Some("local".to_string()),
extensions: None,
kind: Some("Config".to_string()),
api_version: Some("v1".to_string()),
};
let kube_config_options = KubeConfigOptions {
context: None,
cluster: None,
user: None,
};
let config = kube::Config::from_custom_kubeconfig(kube_config, &kube_config_options)
.await
.unwrap();
let client = Client::try_from(config).unwrap(); Hope it helps! Feel free to improve my code. Thanks a lot @teozkr 🎉 |
Beta Was this translation helpful? Give feedback.
You can create a custom
Config
, which you can then build aClient
from.If your API gives you a kubeconfig then you can also use
Config::from_custom_kubeconfig
to load it directly from memory.