Identifying erroneous field in kubernetes deployment spec in C#-client

6/18/2019

I am trying to define a deployment spec using the C#-client of Kubernetes. The values of the fields of my spec are produced by some other application. As such, the deployment sometimes fails and I get an Unprocessable entity(Microsoft.Rest.HttpOperationException) error. However, it is really hard to identify which field results in the Unprocessable entity error.

Can someone tell me how I could get identify the erroneous field?

Here's the trace:

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)
-- LM10
.net
kubernetes

2 Answers

6/19/2019

I was able to get a more detailed error by printing out the Response.Content field of the Microsoft.Rest.HttpOperationException.

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

6/18/2019

All the Kubernetes requests go through the kube-apiserver. The deployment spec needs to comply with the API spec documented here.

You can start by looking at the kube-apiserver logs. You can also work your way backwards if you have a working deployment (Do you have a deployment YAML manifest file?). For example, you can try removing some fields from the YAML manifest of the deployment then run kubectl apply -f deployment.yaml to see if you can reproduce the error.

-- Rico
Source: StackOverflow