问题描述
我一直在使用 Kubernetes .net 客户端库版本来从容器内访问 Kubernetes api。今天我从客户端库版本 1.6.11 更新到 4.0.21,但这破坏了客户端的部分身份验证。
这是我得到的例外:
HttpRequestException. The SSL connection Could not be established,see inner exception.
at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Boolean async,Stream stream,SslClientAuthenticationoptions sslOptions,CancellationToken cancellationToken)
(rest of the stack trace ommited)
内部例外:
AuthenticationException. The remote certificate is invalid because of errors in the certificate chain: PartialChain.
at System.Net.Security.SslStream.SendAuthResetSignal(ProtocolToken message,ExceptiondispatchInfo exception)
at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](TIOAdapter adapter,Boolean receiveFirst,Byte[] reAuthenticationData,Boolean isApm)
at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Boolean async,CancellationToken cancellationToken)
我使用默认的 inClusterConfiguration 创建一个 Kubernetes Client 实例:
KubernetesClientConfiguration config = KubernetesClientConfiguration.InClusterConfig();
Kubernetes client = new Kubernetes(config);
在验证我仍然可以使用与存储在 /var/run/secrets/kubernetes.io/serviceaccount/
中的 pod 服务帐户关联的令牌通过 curl 与 API 通信之后。
我对 SSL 不太熟悉,但经过一番努力后,我找到了一种解决方法,即将 ca.cert 文件从 serviceaccount 目录复制到 /usr/local/share/ca-certificates/
并运行 update-ca-certificates
,但我想知道是什么已更改为现在需要此操作。
是否可以通过某种方式配置客户端,使其自动完成或以其他方式解决?
解决方法
从客户的 Github 中,我发现 this issue 提出了比我发现的更好的解决方法。
KubernetesClientConfiguration config = KubernetesClientConfiguration.InClusterConfig();
config.TcpKeepAlive = false;
Kubernetes client = new Kubernetes(config);