title: Dynamic wildcard subdomain ingress for Kubernetes
body: <p>I'm currently using Kubernetes on GKE to serve the various parts of my product on different subdomains with the Ingress resource. For example: <code>api.mydomain.com</code>, <code>console.mydomain.com</code>, etc.</p>
  
  <p><strong>ingress.yml (current)</strong>:</p>
  
  <pre><code>apiVersion: extensions/v1beta1
  kind: Ingress
  metadata:
    name: ingress
  spec:
    rules:
    - host: api.mydomain.com
      http:
        paths:
          - backend:
              serviceName: api-service
              servicePort: 80
    - host: console.mydomain.com
      http:
        paths:
          - backend:
              serviceName: console-service
              servicePort: 80
  </code></pre>
  
  <p>That works wonderfully, with the L7 GCE load balancer routing to the appropriate places. What I would like to do, however, is deploy many feature-branch deployments as subdomains to test and demonstrate new features before pushing to production. These could be something like <code>new-stylesheet.console.mydomain.com</code> or <code>upgraded-algorithm.api.mydomain.com</code>, inspired by GitLab CI's <a href="https://docs.gitlab.com/ce/ci/environments.html" rel="noreferrer">environments</a>.</p>
  
  <p>Here's a potential workflow for each deployment:</p>
  
  <ol>
  <li>Create feature-api-deployment.yml</li>
  <li>Create feature-api-service.yml</li>
  <li>Update ingress.yml with new subdomain rule: <code>feature.api.mydomain.com</code> specifying <code>serviceName: feature-api-service</code></li>
  </ol>
  
  <p>But enumerating and maintaining all subdomain->service mappings will get messy with tearing down deployments, and create a ton of GCE backends (default quota is 5...) so it's not ideal.</p>
  
  <p>Is there anything built in to Kubernetes that I'm overlooking to handle this? Something like this would be ideal to pick a target service based on a matched subdomain:</p>
  
  <p><strong>ingress.yml (wanted)</strong></p>
  
  <pre><code>apiVersion: extensions/v1beta1
  kind: Ingress
  metadata:
    name: ingress
  spec:
    rules:
    - host: *.api.mydomain.com
      http:
        paths:
          - backend:
              serviceName: {value of *}-api-service
              servicePort: 80
  </code></pre>