Careful!

You are browsing documentation for the next version of Kuma. Use this version at your own risk.

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
apiVersion: kuma.io/v1alpha1
kind: HostnameGenerator
metadata:
  name: all
  namespace: kuma-system
  labels:
    kuma.io/mesh: 
spec:
  selector:
    meshService:
      matchLabels:
        k8s.kuma.io/namespace: kuma-demo
  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:

kind: MeshService
metadata:
  name: redis
  namespace: kuma-demo
  labels:
    kuma.io/mesh: products
    team: backend
    k8s.kuma.io/service-name: redis
    k8s.kuma.io/namespace: kuma-demo

and

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

the generated hostname would be:

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:

status:
  addresses:
    - hostname: redis.kuma-demo.mesh
      origin: HostnameGenerator
      hostnameGeneratorRef:
        coreName: all