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?
CodePudding user response:
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.