Ask Your Question

Revision history [back]

click to hide/show revision 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:

  1. Load the client certificate and key into memory:
var certificate = new X509Certificate2("client.crt");
var privateKey = File.ReadAllText("client.key");
  1. Create a new instance of 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)
};
  1. Use the config object to create a new instance of Kubernetes client:
var client = new Kubernetes(config);
  1. You can then use the 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.