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.

--

--

--

DevOps engineer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Nov 2019 Platform Update: 2 new blocks new path actions, Mobile Optimized website and more!

The Best Domain Name Registrars 2021

Are We There Yet? Defining Product Release Criteria

A sign that asks “Are we there yet?” three times.

Advent of Cyber 3 Day 14 — Dev(Insecure)Ops Walkthrough

What is IaaS vs SaaS vs PaaS and XaaS: what’s the difference. Examples

Algorithm & Scratch

Falling in love with what I hated the most!!

The Language of Games & Naked Self Interest, in Context of Central Banking

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Saket Jain

Saket Jain

DevOps engineer

More from Medium

Kubernetes Ingress with Traefik ingress

Configuring Argo CD on a multi-node Hetzner Cloud

Backup etcd in Kubernetes (and Restore)

Prune Container Images from Rancher using Kubernetes CronJob and Binaries