<p>I'm setting up Ingress controller for my service in deployment.yaml of Kubernetes. </p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: {env}
  annotations:
    traefik.ingress.kubernetes.io/frontend-entry-points: "http,https"
    ingress.kubernetes.io/force-hsts: "true"
    traefik.ingress.kubernetes.io/redirect-regex: ^http://(.*)
    traefik.ingress.kubernetes.io/redirect-replacement: https://$1
    kubernetes.io/ingress.class: "traefik"

spec:
  rules:
    - host: “qa.mywebsite.com"
      http:
        paths:
          - backend:
              serviceName: serviceName-{env}
              servicePort:8080
</code></pre>

<p>How can I set it up Ingress controller so that the traffic in QA pods are routed to the QA end point, Prod prods' traffic are routed to Prod pods?</p>

<p><strong>The separation of environment for different stages is one of the important factor in deploying application in Kuebernetes.</strong></p>

<p>I would recommend here to create two separate ingress.</p>

<p>One for Production and another one for QA. (If you have more environment, you can have more). <strong>Ingress Rules would be controlled based on host.</strong></p>

<p>QA environment ingress could be like this.</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: {env}
  annotations:
    traefik.ingress.kubernetes.io/frontend-entry-points: "http,https"
    ingress.kubernetes.io/force-hsts: "true"
    traefik.ingress.kubernetes.io/redirect-regex: ^http://(.*)
    traefik.ingress.kubernetes.io/redirect-replacement: https://$1
    kubernetes.io/ingress.class: "traefik"

spec:
  rules:
    - host: “qa.mywebsite.com"
      http:
        paths:
          - backend:
              serviceName: serviceName-{env}
              servicePort:8080
</code></pre>

<p>Similarly you can also have another ingress in Production Environment(host is different here).</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: {env}
  annotations:
    traefik.ingress.kubernetes.io/frontend-entry-points: "http,https"
    ingress.kubernetes.io/force-hsts: "true"
    traefik.ingress.kubernetes.io/redirect-regex: ^http://(.*)
    traefik.ingress.kubernetes.io/redirect-replacement: https://$1
    kubernetes.io/ingress.class: "traefik"

spec:
  rules:
    - host: “prod.mywebsite.com"
      http:
        paths:
          - backend:
              serviceName: serviceName-{env}
              servicePort:8080 
</code></pre>
