2

I have created an Elasticsearch resource using the below yaml manifest after installing the eck-operator as mentioned here.

apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
  name: quickstart
spec:
  version: 7.15.0
  nodeSets:
  - name: default
    count: 1
    config:
      node.store.allow_mmap: false

After this manifest is applied, I can get the status manually by executing:

kubectl get elasticsearch -n ecknamespace

and the output would be as follows:

> $ kubectl get elasticsearch -n ecknamespace
  NAME          HEALTH   NODES  VERSION   PHASE   AGE 
  quickstart    green    3       7.15.0   Ready   3d17h

Using the Kubernetes C# Client, how do I get the above data programmatically?

Neuron
  • 5,141
  • 5
  • 38
  • 59
Jerald Baker
  • 1,121
  • 1
  • 12
  • 48
  • is this related to java? – Neuron Oct 05 '21 at 09:04
  • the APIs of java and C# k8s client are similar, so the implementation would be similar – Jerald Baker Oct 05 '21 at 09:14
  • if you add the java tag, then java developers will see this post and probably be a bit cranky that the question is not about java. tags should be precise, it's not an exercise of adding as many as possible :) – Neuron Oct 05 '21 at 09:18

1 Answers1

1

The client includes an example of how to interact with custom resources.

It will require you to define the classes described in the files cResource.cs and CustomResourceDefinition.cs.

Afterwards, the following code should list the elasticsearch resource:

var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
var client = new GenericClient(config,  "elasticsearch.k8s.elastic.co", "v1", "elasticsearches");
var elasticSearches = await client.ListNamespacedAsync<CustomResourceList<CResource>>("default").ConfigureAwait(false);
foreach (var es in elasticSearches.Items)
{
    Console.WriteLine(es.Metadata.Name);
}

EDIT after OP's comments: to view all fields of the custom resource, one needs to edit the CustomResource class (file CustomResourceDefinition.cs in the example) with the corresponding fields.

johnnyaug
  • 887
  • 8
  • 24
  • I tried that - however i am not getting the "HEALTH", "PHASE" and other fields shown in the output of kubectl get elasticsearch – Jerald Baker Oct 05 '21 at 11:23
  • In the future, please describe your previous attempts and their results in the question. Also, can you please add to your original question the output of `kubectl get elasticsearch -n ecknamespace -o json`? This way I can edit my answer to include the fields. – johnnyaug Oct 05 '21 at 11:33
  • I got it, I stepped into the function ListNamespacedAsync and see those fields coming in the response JSON. Those fields go missing during deserialization due to my customresource class structure. – Jerald Baker Oct 05 '21 at 11:42