微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Kubernetes 客户端库 AuthenticationException

如何解决Kubernetes 客户端库 AuthenticationException

我一直在使用 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);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。