You can use the custom resource ComponentTemplate
to manage the component template inside Elasticsearch.
You can use the following properties:
- elasticsearchRef (object): The Elasticsearch cluster ref
- managed (object): Use it if cluster is deployed with this operator
- name (string / required): The name of elasticsearch resource.
- namespace (string): The namespace where cluster is deployed on. Not needed if is on same namespace.
- targetNodeGroup (string): The node group where operator connect on. Default is used all node groups.
- external (object): Use it if cluster is not deployed with this operator.
- addresses (slice of string): The list of IPs, DNS, URL to access on cluster
- secretRef (object): The secret ref that store the credentials to connect on Elasticsearch. It need to contain the keys
username
andpassword
. It only used for external Elasticsearch.- name (string / require): The secret name.
- elasticsearchCASecretRef (object). It's the secret that store custom CA to connect on Elasticsearch cluster.
- name (string / require): The secret name
- managed (object): Use it if cluster is deployed with this operator
- name (string): The component template name. Default it use the resource name.
- settings (string): The component setting in JSON string format. Default to empty.
- mappings (string): The component mapping in JSON string format. Default to empty.
- aliases (string): The component alias in JSON string format. Default to empty.
- rawTemplate (string): The component in raw format (JSON string format). You can use it instead to set settings, mappings and aliases. It can be usefull if component is generated by ECS for exemple. Default to empty.
In this sample, we will create component template on managed Elasticseach.
component.yml:
apiVersion: elasticsearchapi.k8s.webcenter.fr/v1
kind: ComponentTemplate
metadata:
name: test
namespace: cluster-dev
spec:
settings: |
{
"number_of_shards": 1
}
mappings: |
{
"_source": {
"enabled": false
},
"properties": {
"host_name": {
"type": "keyword"
},
"created_at": {
"type": "date",
"format": "EEE MMM dd HH:mm:ss Z yyyy"
}
}
}
elasticsearchRef:
managed:
name: elasticsearch
Or if you prefer in raw format
component.yml:
apiVersion: elasticsearchapi.k8s.webcenter.fr/v1
kind: ComponentTemplate
metadata:
name: test
namespace: cluster-dev
spec:
rawTemplate: |
{
"settings": {
"number_of_shards": 1
},
"mappings": {
"_source": {
"enabled": false
},
"properties": {
"host_name": {
"type": "keyword"
},
"created_at": {
"type": "date",
"format": "EEE MMM dd HH:mm:ss Z yyyy"
}
}
}
}
elasticsearchRef:
managed:
name: elasticsearch
In this sample, we will create component template on external Elasticsearch.
component.yml:
apiVersion: elasticsearchapi.k8s.webcenter.fr/v1
kind: ComponentTemplate
metadata:
name: test
namespace: cluster-dev
spec:
settings: |
{
"number_of_shards": 1
}
mappings: |
{
"_source": {
"enabled": false
},
"properties": {
"host_name": {
"type": "keyword"
},
"created_at": {
"type": "date",
"format": "EEE MMM dd HH:mm:ss Z yyyy"
}
}
}
elasticsearchRef:
external:
addresses:
- https://elasticsearch-cluster-dev.domain.local
secretRef:
name: elasticsearch-credentials
elasticsearchCASecretRef:
name: custom-ca-elasticsearch
custom-ca-elasticsearch-secret.yaml:
apiVersion: v1
kind: Secret
metadata:
name: custom-ca-elasticsearch
namespace: cluster-dev
type: Opaque
data:
ca.crt: ++++++++
elasticsearch-credentials.yaml:
apiVersion: v1
kind: Secret
metadata:
name: elasticsearch-credentials
namespace: cluster-dev
type: Opaque
data:
username: ++++++++
password: ++++++++