Add additional annotations to the existing helm chart

My scenario for this blog was I want to add some annotations to the metadata block of service within an existing helm chart (I have to add an annotation for Prometheus so that the service is auto-discovered)

Helm chart is a popular method of packaging applications to be installed on the Kubernetes cluster. As Helm chart developers, we have to decide what configurations need to be made available to the customer and how should they be offered. In this article, we look at configuring labels and annotations. All Kubernetes objects should have a set of labels for external tools to identify and use them in a consistent manner. Specifying labels and annotations involves solving some key challenges.

Annotations

As mentioned, annotations are arbitrary key/value pairs that are added to the existing Kubernetes definitions. One common use case is that of service discovery for the Prometheus time-series database.

Service YAML

Service with mandatory labels required of all Kubernetes objects and customer-provided annotations.

metadata:  
annotations:
{{ toYaml .Values.SERVICE.ANNOTATIONS | indent 4 }}

Deployment vars default YAML

  • prometheus.io/path: "/actuator/prometheus": Which endpoint to make the HTTP request to
  • prometheus.io/port: '8080': On which port to make the HTTP request
  • prometheus.io/scrape: 'Trueโ€™: Whether to enable scraping this resource

Running the upgrade command will trigger the update:

$ helm upgrade --install <name of your service> .

we can see our annotation! applied successfully command below to validate

$ kubectl describe service <name of the service> -n <namespace>
kind: Service
apiVersion: v1
metadata:
name: <name of the service>
namespace: <namespace>
selfLink: /api/v1/namespaces/<namespace>/services/<name of the service>
uid: 4a3de942-b2ce-453e-888e-13c04333f7d5
resourceVersion: '77637655'
creationTimestamp: '2021-09-21T15:05:32Z'
labels:
app: rider-service
app.kubernetes.io/managed-by: Helm
annotations:
meta.helm.sh/release-name: <name of the service>
meta.helm.sh/release-namespace: <namespace>
prometheus.io/path: /actuator/prometheus
prometheus.io/port: '8080'
prometheus.io/scrape: 'true'

Conclusion

Labels and annotations are one of the main foundations for Kubernetes. They are both ways of adding metadata to Kubernetes objects. Kubernetes labels allow us to identify, select, and operate on Kubernetes objects, whereas annotations are non-identifying metadata.

They are used by external tools to help them to provide extra functionalities. However, there are no standard practices enforced. In this article, we attempted to provide a guideline that will serve as best practices when labeling and annotating Kubernetes objects.

--

--

๐’๐š๐ค๐ž๐ญ ๐‰๐š๐ข๐ง
๐’๐š๐ค๐ž๐ญ ๐‰๐š๐ข๐ง

Written by ๐’๐š๐ค๐ž๐ญ ๐‰๐š๐ข๐ง

๐ƒ๐ž๐ฏ๐Ž๐ฉ๐ฌ/๐’๐‘๐„/๐‚๐ฅ๐จ๐ฎ๐ /๐ˆ๐ง๐Ÿ๐ซ๐š๐ฌ๐ญ๐ซ๐ฎ๐œ๐ญ๐ฎ๐ซ๐ž /๐’๐ฒ๐ฌ๐ญ๐ž๐ฆ ๐„๐ง๐ ๐ข๐ง๐ž๐ž๐ซ

Responses (1)