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).

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...