|
| 1 | +--- |
| 2 | +applies_to: |
| 3 | + deployment: |
| 4 | + eck: preview 3.1 |
| 5 | +products: |
| 6 | + - id: cloud-kubernetes |
| 7 | +--- |
| 8 | + |
| 9 | +# Propagate Labels and Annotations [k8s-propagate-labels-annotations] |
| 10 | + |
| 11 | +Starting with version `3.1.0`, {{eck}} supports propagating labels and annotations from the parent resource to the child resources it creates. This can be used on all custom resources managed by ECK, such as {{eck_resources_list}}. |
| 12 | + |
| 13 | +The example below demonstrates how to use this feature on a {{es}} cluster, however, as mentioned above, this can be also applied to any custom resource managed by {{eck}}. |
| 14 | + |
| 15 | +```yaml |
| 16 | +apiVersion: elasticsearch.k8s.elastic.co/v1 |
| 17 | +kind: Elasticsearch |
| 18 | +metadata: |
| 19 | + annotations: |
| 20 | + # Some custom annotations to be propagated to resources created by the operator. |
| 21 | + my-annotation1: "my-annotation1-value" |
| 22 | + my-annotation2: "my-annotation2-value" |
| 23 | + # Instructions for the operator to propagate these annotations and labels to resources it creates. |
| 24 | + eck.k8s.alpha.elastic.co/propagate-annotations: "my-annotation1, my-annotation2" |
| 25 | + eck.k8s.alpha.elastic.co/propagate-labels: "my-label1, my-label2" |
| 26 | + labels: |
| 27 | + # Some custom labels to be propagated to resources created by the operator. |
| 28 | + my-label1: "my-label1-value" |
| 29 | + my-label2: "my-label2-value" |
| 30 | + name: elasticsearch-sample |
| 31 | +spec: |
| 32 | + version: 9.1.0 |
| 33 | + nodeSets: |
| 34 | + - name: default |
| 35 | + config: |
| 36 | + # this allows ES to run on nodes even if their vm.max_map_count has not been increased, at a performance cost |
| 37 | + node.store.allow_mmap: false |
| 38 | + count: 1 |
| 39 | +``` |
| 40 | +
|
| 41 | +The custom labels and annotations specified in the `metadata` section of the parent resource will be propagated to all child resources created by {{eck}}, such as StatefulSets, Pods, Services, and Secrets. This ensures that all resources have consistent metadata, which can be useful for filtering, monitoring, and managing resources in Kubernetes: |
| 42 | + |
| 43 | +```sh |
| 44 | +kubectl get sts,pods,svc -l my-label1=my-label1-value,my-label2=my-label2-value |
| 45 | +``` |
| 46 | + |
| 47 | +```sh |
| 48 | +NAME READY AGE |
| 49 | +statefulset.apps/elasticsearch-sample-es-default 1/1 4m10s |
| 50 | +
|
| 51 | +NAME READY STATUS RESTARTS AGE |
| 52 | +pod/elasticsearch-sample-es-default-0 1/1 Running 0 4m9s |
| 53 | +
|
| 54 | +NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE |
| 55 | +service/elasticsearch-sample-es-default ClusterIP None <none> 9200/TCP 4m12s |
| 56 | +service/elasticsearch-sample-es-http ClusterIP XX.XX.XX.XX <none> 9200/TCP 4m14s |
| 57 | +service/elasticsearch-sample-es-internal-http ClusterIP XX.XX.XX.XX <none> 9200/TCP 4m14s |
| 58 | +service/elasticsearch-sample-es-transport ClusterIP None <none> 9300/TCP 4m14s |
| 59 | +``` |
| 60 | + |
| 61 | +It is possible to use `*` as a wildcard to propagate all labels and annotations from the parent resource to the child resources. For example: |
| 62 | + |
| 63 | +```yaml |
| 64 | +apiVersion: elasticsearch.k8s.elastic.co/v1 |
| 65 | +kind: Elasticsearch |
| 66 | +metadata: |
| 67 | + annotations: |
| 68 | + # Instructions for the operator to propagate all the annotations and labels to resources it creates. |
| 69 | + eck.k8s.alpha.elastic.co/propagate-annotations: "*" |
| 70 | + eck.k8s.alpha.elastic.co/propagate-labels: "*" |
| 71 | + name: elasticsearch-sample |
| 72 | +spec: |
| 73 | + version: 9.1.0 |
| 74 | + nodeSets: |
| 75 | + - name: default |
| 76 | + config: |
| 77 | + # this allows ES to run on nodes even if their vm.max_map_count has not been increased, at a performance cost |
| 78 | + node.store.allow_mmap: false |
| 79 | + count: 1 |
| 80 | +``` |
| 81 | + |
| 82 | +::::{note} |
| 83 | +Note the following considerations when using this feature: |
| 84 | +* Propagated labels and annotations are not automatically deleted. If you want to remove them from the child resources, you need to do so manually or use a cleanup script. |
| 85 | +* To prevent conflicts, some labels and annotations reserved for internal use by ECK or Kubernetes are not propagated. This is the case for labels and annotations that match `*.k8s.*.elastic.co/` and also `kubectl.kubernetes.io/last-applied-configuration`. |
| 86 | +:::: |
0 commit comments