'How to automate versioning in kubernetes Ingress

I have a multiple application deployed on kubernetes with multiple host. I want to configure versioning for the deployed apps. There will be multiple version for each app (/v1, /v2 ...). I have configured a pipeline to deploy app on TAG and created deployment and service for new version But how can I update New tag verison and update it in ingress controller.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
    cert-manager.io/issuer: "letsencrypt-prod"
spec:
  ingressClassName: nginx
  rules:
    - host: app1.com
      http:
        paths:
          - pathType: Prefix
            backend:
              service:
                name: app1
                port:
                  number: 3000
            path: /
          - pathType: Prefix
            backend:
              service:
                name: app1-v1.0.0
                port:
                  number: 3000
            path: /v1

How I can Update new version(app1-v1.1.0) in ingress file using automation? Also when I create TAG v2.0.0 it should create new service app1-v2.0.0 and point the backend with /v2.



Solution 1:[1]

First of all, this has barely anything to do with GitLab, except for the fact that you're using it to host your codebase..


To answer your question - I would just use Kustomize. It's already built into kubectl, so no need to install separate packages.

Since it seems like you want to have the same ingress, you'll have to play around a bit and figure it out, because you can't just create a new template for the every tag and overwrite the current ingress.

The way you're requesting it, you'll have to re-generate the ingress manifest, add the route for each tag, and then apply it manifest.

Basically, you'll have to do some scripting - fetch all tags from GitLab's API, and for each of them add a route in your ingress definition.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 aljaxus