1 | initial version |
To activate TLS authentication for the C# Kubernetes client in the absence of a kubeconfig file, you need to use the client certificates to authenticate with the Kubernetes API server.
Here are the steps to follow:
var certificate = new X509Certificate2("client.crt");
var privateKey = File.ReadAllText("client.key");
KubernetesClientConfiguration
and set the ClientCertificateData
and ClientKeyData
properties:var config = new KubernetesClientConfiguration
{
Host = "https://kubernetes-api-server-url",
SkipTlsVerify = false,
ClientCertificateData = certificate.Export(X509ContentType.Cert),
ClientKeyData = Encoding.UTF8.GetBytes(privateKey)
};
config
object to create a new instance of Kubernetes
client:var client = new Kubernetes(config);
client
object to interact with the Kubernetes API server.Note: Make sure to keep the client certificate and key secure as they provide access to the Kubernetes API server.