<p>I have been with <code>K8s-ingress</code> well so far but I have a question.</p>

<p>Can <code>ingress</code> route requests based on <strong>IP</strong>?</p>

<p>I've already know that ingress do routing based on hosts like a.com, b.com... to each services and URI like path /a-service/<em>, /b-service/</em> to each services.</p>

<p>However, I'm curious with the idea that <code>Ingress</code> can route by <strong>IP</strong>? I'd like requests from my office(certain ip) to route a specific service for tests.</p>

<p>Does it make sense? and any idea for that?</p>

<p>If this is just for testing I would just whitelist the IP. You can read the docs about <a href="https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#whitelist-source-range" rel="nofollow noreferrer">nginx ingress annotations</a></p>

<blockquote>
  <p>You can specify allowed client IP source ranges through the <code>nginx.ingress.kubernetes.io/whitelist-source-range</code> annotation. The value is a comma separated list of <a href="https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing" rel="nofollow noreferrer">CIDRs</a>, e.g. <code>10.0.0.0/24,172.10.0.1</code>.</p>
</blockquote>

<p>Example yaml might look like this:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: whitelist
  annotations:
    nginx.ingress.kubernetes.io/whitelist-source-range: "1.1.1.1/24"
spec:
  rules:
  - host: foo.bar.com
    http:
      paths:
      - path: /
        backend:
          serviceName: echoheaders
          servicePort: 80
</code></pre>

<p>Also it looks like you can do that in <a href="https://istio.io/" rel="nofollow noreferrer">Istio</a> (I did not tried it) in <strong>kind</strong> <code>ServiceRole</code> and <code>ServiceRoleBinding</code> for specifying detailed access control requirements. For this you would use <code>source.ip</code> property. It's explained on <a href="https://istio.io/docs/reference/config/authorization/constraints-and-properties/" rel="nofollow noreferrer">Constraints and Properties</a></p>
