<h1>Scenario</h1>
<p>I'm using the <a href="https://martinfowler.com/bliki/CQRS.html" rel="nofollow noreferrer">CQRS pattern</a> for REST services that deal with Sales as in the diagram below. (The question focuses on the REST services.)</p>
<p><a href="https://i.stack.imgur.com/be2mZ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/be2mZ.jpg" alt="CQRS example" /></a></p>
<p>On K8S I have:</p>
<ul>
<li>A microservice for GET endpoints (queries) that runs on a given pod.</li>
<li>Another microservice for POST and PUT endpoints (commands) tat runs on a different pod.</li>
</ul>
<p>Both operate on the same <em>resource</em>: Sales. The natural URL mapping would be:</p>
<ul>
<li>GET endpoints on <code>mydomain.com/api/sales/*</code> should go to the first pod.</li>
<li>POST and PUT endpoints on <code>mydomain.com/api/sales/*</code> should go to the second pod.</li>
</ul>
<h1>Ingress</h1>
<p>To deploy these two microservices to a K8S cluster, I define a separate <code>Service</code> and <code>Deployment</code> for each. Then I create an <code>Ingress</code> definition to route requests to the Services:</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
spec:
  rules:
    - host: mydomain.com
      http:
        paths:
          - path: /api/sales
            pathType: Prefix
            backend:
              service:
                name: sales-queries-service
                port:
                  name: 80
          - path: /api/sales
            pathType: Prefix
            backend:
              service:
                name: sales-commands-service
                port:
                  name: 80     
  ingressClassName: ingress-nginx
</code></pre>
<h3>Problem</h3>
<p>The ingress definition above does not work because it has the mapping of the same path <code>/api/sales</code> to two different services. As such, it's non deterministic.</p>
<p>It's a <a href="https://github.com/kubernetes/ingress-nginx/issues/187#issuecomment-499626492" rel="nofollow noreferrer">feature desired by many</a> that the ingress spec can allow the specification of the HTTP methods. In fact, when I asked ChatGPT it suggested adding this snippet to my ingress yaml, but unfortunately it's a parameter that doesn't exist... yet.</p>
<pre><code>    httpMethods:
      - GET
</code></pre>
<p>Is there any other option to specify the routing in a K8S cluster (without installing an API gateway product)?</p>

Paulo Merson
<p>You can Install and Traefik and use IngressRoutes which supports <a href="https://stackoverflow.com/questions/75871477/how-to-route-http-requests-on-kubernetes-based-on-the-http-methods/75917900?r=SearchResults#75917900">Http method routing</a>.</p>
<p>so you can Method() rule to point your requests toward desired services.</p>
