Great question wheresh. I had the exact same question too. And I was extremely confused.
I think (please someone correct me if I'm wrong) that the action labelmap actually creates a new set of labels, instead of relabeling the labels:
"labelmap: Match regex against all label names. Then copy the values of the matching labels to label names given by replacement..."
Also, I think that labelmap is not a replace action because all replace actions require a target_label:
# Label to which the resulting value is written in a replace action.
# It is mandatory for replace actions. Regex capture groups are available.
[ target_label: <labelname> ]
So I think it just creates a new set of labels.
The default replacement is $1, and in the example what is being captured in "regex: __meta_kubernetes_service_label_(.+)" is the very last part.
So this is what I think is happening:
Labels that were matched New Labels
_meta_kubernetes_service_label_somelabel1 -> somelabel1
_meta_kubernetes_service_label_somelabel2 -> somelabel2
_meta_kubernetes_service_label_somelabel3 -> somelabel3
_meta_kubernetes_service_label_somelabel4 -> somelabel4
_meta_kubernetes_service_label_somelabel5 -> somelabel5
Someone please either confirm that this is what is happening, or provide an explanation of what is actually happening.
Thank you!