首页 > 解决方案 > 在 C#-client 中识别 kubernetes 部署规范中的错误字段

问题描述

我正在尝试使用 Kubernetes 的 C#-client 定义部署规范。我的规范字段的值是由其他一些应用程序产生的。因此,部署有时会失败并且我收到Unprocessable entity(Microsoft.Rest.HttpOperationException) 错误。但是,很难确定哪个字段会导致 Unprocessable entity 错误。

有人可以告诉我如何识别错误的字段吗?

这是跟踪:

Microsoft.Rest.HttpOperationException: Operation returned an invalid status code 'UnprocessableEntity'
   at k8s.Kubernetes.CreateNamespacedDeploymentWithHttpMessagesAsync(V1Deployment body, String namespaceParameter, String dryRun, String fieldManager, String pretty, Dictionary`2 customHeaders, CancellationToken cancellationToken)
   at k8s.KubernetesExtensions.CreateNamespacedDeploymentAsync(IKubernetes operations, V1Deployment body, String namespaceParameter, String dryRun, String fieldManager, String pretty, CancellationToken cancellationToken)
   at k8s.KubernetesExtensions.CreateNamespacedDeployment(IKubernetes operations, V1Deployment body, String namespaceParameter, String dryRun, String fieldManager, String pretty)

标签: .netkubernetes

解决方案


通过打印出 Microsoft.Rest.HttpOperationException 的 Response.Content 字段,我能够得到更详细的错误。

try
{
    // Code for deployment
}
catch(Microsoft.Rest.HttpOperationException e)
{
    Console.WriteLine(e.Response.Content);
}

推荐阅读