3

At a previous job, we had a lot of excessive issues with versioning of our APIs, to the point where we had whole server farms for our services that were running specific versions for specific applications, split out in case the Mobile Team updated but the Web team did not (there were about 5 such front end teams so 5 server farms, which was a pain and expensive).

While I don't work for them anymore, I have been working on bringing in another team to use our APIs, and they are notoriously slow on fixing deprecation issues, while our team has been in a pretty rapid development pace. Since we use Azure Kubernetes, I was wanting to do something like this:

Say the endpoint I want to access is /api/user/ and I have multiple versions of this api (let's say V1, V2, V3). How would I go about configuring kubernetes so that the route is /{version}/api/user with the route of /api/user/ going to the "latest" version?

To clarify, let's assume I have deployments for each of these version: Deployment for V1 Deployment for V2 Deployment for V3

I think this issue could be gotten around by doing some kind of routing via tags (we already route based on service domain, so expanding that slightly to include service domain + version shouldn't be bad) but how would I accomplish the concept of the "base" url when they do not provide a version? Is it even a good idea to include a "base" url? (My idea behind this is that our app will always use the latest, but that might be a bad idea).

Marshall Tigerus
  • 550
  • 5
  • 13
  • To clarify, you have different container/pods running with different versions of a REST API, correct? Assuming that is the case, I'm not clear on what is routing the requests now. Is that something built into Azure Kubernetes or is there some sort of reverse proxy? Also you mention "the first question" but I only see one question. Is there something else? – JimmyJames Nov 10 '20 at 15:57
  • I've modified the above, but yes, the idea is that we would have a deployment running for each of the "versions" of the code, tagged with the appropriate tag, and route based on that. The difficult part conceptually is routing a "base" url to the latest version. – Marshall Tigerus Nov 10 '20 at 18:46
  • OK, that helps. I'm still not sure what is doing the routing here. I'm not familiar with Azure Kubernetes. This seems pretty straightforward from a reverse proxy perspective. If this is specific to Azure, this is the wrong forum, I think. – JimmyJames Nov 10 '20 at 18:52

1 Answers1

1

If you are on k8s, you can use an Ingress resource to do that.

You probably already have one, this is the one that routes around traffic for you. If not, it needs an ingress-controller, like nginx. This will be in its own namespace (basically global for all namespaces).

Then you create an Ingress resource in your own namespace, and the controller will pick it up and configure the rules for you.

It looks like this:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: api-ingress
spec:
  rules:
  - host: api.company.com
    http:
      paths:
      - pathType: Prefix
        path: "/v1" 
        backend:
          service:
            name: v1-api
            port:
             number: 8080
      - pathType: Prefix
        path: "/v2" 
        backend:
          service:
            name: v2-api
            port:
              number: 8080
      - pathType: Prefix
        path: "/api" 
        backend:
          service:
            name: base-api
            port:
              number: 8080

I assume you have services under the name of v1-api, v2-api and so on...

Robert Bräutigam
  • 11,473
  • 1
  • 17
  • 36
  • 1
    thanks for the validation, that's more or less what I thought but couldn't quite get there. Now I just need to figure out how to automate this so that when I push a new build it updates everything. – Marshall Tigerus Nov 10 '20 at 21:38
  • For some reason this popped up on my frontpage today but did you ever find out how to automate this @MarshallTigerus – SirHawrk Aug 03 '22 at 09:31
  • @SirHawrk I did not pursue it further, unfortunately. – Marshall Tigerus Sep 30 '22 at 20:17