Home > Back-end >  How can I optimize ingress yaml file
How can I optimize ingress yaml file

Time:11-18

I have this ingress file in yaml format. I see a lot of repetition at host at and service level. I have many routes that point to service_2. How can I reduce the size and numbers of code lines? I have only one domain xx.com.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  namespace: default
  name: ingress
  annotations:
    acme.cert-manager.io/http01-edit-in-place: "true"
    ingress.kubernetes.io/ssl-redirect: "false"
spec:
  tls:
  - hosts:
    - xx.com
    secretName: xx
  rules:
  - host: xx.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: servic_1
            port:
              number: 3000
  - host: xx.com 
    http:
      paths:
      - path: /api_2
        pathType: Prefix
        backend:
          service:
            name: service_2
            port:
              number: 8000
  - host: xx.com 
    http:
      paths:
      - path: /api_3
        pathType: Prefix
        backend:
          service:
            name: service_2
            port:
              number: 8000

CodePudding user response:

You can create multiple paths for a host

  rules:
  - host: xx.com
    http:
      paths:
      - path: /
        ...
      - path: /api_2
        ...
      - path: /api_3
        ...
  • Related