HostnameGenerator

This resource is experimental!

A HostnameGenerator provides

  • a template to generate hostnames from properties of MeshServices and MeshExternalServices
  • a selector that defines for which MeshServices and MeshExternalServices this generator runs

  • Kubernetes

  • Universal
  1. apiVersion: kuma.io/v1alpha1
  2. kind: HostnameGenerator
  3. metadata:
  4. name: all
  5. namespace: kuma-system
  6. labels:
  7. kuma.io/mesh:
  8. spec:
  9. selector:
  10. meshService:
  11. matchLabels:
  12. k8s.kuma.io/namespace: kuma-demo
  13. template: "{{ .DisplayName }}.{{ .Namespace }}.mesh"
  1. type: HostnameGenerator
  2. name: all
  3. spec:
  4. selector:
  5. meshService:
  6. matchLabels:
  7. k8s.kuma.io/namespace: kuma-demo
  8. template: "{{ .DisplayName }}.{{ .Namespace }}.mesh"

Template

A template is a golang text template. It is run with the function label to retrieve labels of the MeshService or MeshExternalService as well as the following attributes:

  • .DisplayName: the name of the resource in its original zone
  • .Namespace: the namespace of the resource in its original zone, if kubernetes
  • .Zone: the zone of the resource
  • .Mesh: the mesh of the resource

For example, given:

  1. kind: MeshService
  2. metadata:
  3. name: redis
  4. namespace: kuma-demo
  5. labels:
  6. kuma.io/mesh: products
  7. team: backend
  8. k8s.kuma.io/service-name: redis
  9. k8s.kuma.io/namespace: kuma-demo

and

  1. template: "{{ .DisplayName }}.{{ .Namespace }}.{{ .Mesh }}.{{ label "team" }}.mesh"

the generated hostname would be:

  1. redis.kuma-demo.products.backend.mesh

Currently the generated hostname points to the first VIP known for the MeshService.

Status

Every generated hostname is recorded on the MeshService status in addresses:

  1. status:
  2. addresses:
  3. - hostname: redis.kuma-demo.mesh
  4. origin: HostnameGenerator
  5. hostnameGeneratorRef:
  6. coreName: all