Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I join a ALB ingress group instead of overriding an existing one in EKS?

I am deploying K8S to AWS EKS cluster and use ALB for the deployments. I'd like to use one ALB for multiple services but I can't figure out how to share the same ALB. Every time I deploy a ingress it will override an existing one.

I have two config yaml file:

a.yaml

---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: sample-ingress
  namespace: default
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/group.name: sample-ingress
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/target-type: ip
    alb.ingress.kubernetes.io/group.order: '1'
spec:
  rules:
    - http:
        paths:
          - path: /sample-app/*
            backend:
              serviceName: sample-entrypoint
              servicePort: 80

b.yaml

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: sample-ingress
  namespace: default
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/group.name: sample-ingress
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/target-type: ip
    alb.ingress.kubernetes.io/group.order: '2'
spec:
  rules:
    - http:
        paths:
          - path: /sample-es/*
            backend:
              serviceName: sample-es-entrypoint
              servicePort: 9200

I'd like both share the same ALB so I specify the group name to be the same:

alb.ingress.kubernetes.io/group.name: sample-ingress

I also specify a different order in the two files.

but when I run kubectl apply -f a.yaml, It creates a ALB with the rule I specified in the config file: /sample-app/*. But when I run kubectl apply -f b.yaml, it overrides the existing rule with /sample-es/*. So how can I make both share the same ALB and allow them provide different rules?

like image 601
Joey Yi Zhao Avatar asked Sep 01 '25 03:09

Joey Yi Zhao


1 Answers

I guess you can create separate ingress and attach them to the same service configuration. Point the service configuration with alb, and that should work. I have a configuration for internal-facing services, please see if this works for you.

apiVersion: v1
kind: Service
metadata:
  annotations:
    service.beta.kubernetes.io/aws-load-balancer-internal: 0.0.0.0/0
  labels:
    app.kubernetes.io/instance: goldendev-ingress-test
    app.kubernetes.io/managed-by: Tiller
    app.kubernetes.io/name: ingress-test
    environment: DEV
    helm.sh/chart: ingress-test
  name: ingress-test
  namespace: default
spec:
  externalTrafficPolicy: Cluster
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: 8080
  selector:
    app.kubernetes.io/instance: z1
    app.kubernetes.io/name: gunicorn
  sessionAffinity: None
  type: LoadBalancer

Ingress.yaml

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: sample-ingress
  namespace: default
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/group.name: sample-ingress
    alb.ingress.kubernetes.io/scheme: internal
    alb.ingress.kubernetes.io/target-type: ip
    alb.ingress.kubernetes.io/group.order: '1'
spec:
  rules:
    - http:
        paths:
          - path: /mappings/v1/hello/*
            backend:
              serviceName: ingress-test
              servicePort: 80
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: sample-ingress-1
  namespace: default
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/group.name: sample-ingress
    alb.ingress.kubernetes.io/scheme: internal
    alb.ingress.kubernetes.io/target-type: ip
    alb.ingress.kubernetes.io/group.order: '2'
spec:
  rules:
    - http:
        paths:
          - path: /mappings/v1/teams/*
            backend:
              serviceName: ingress-test-2
              servicePort: 80

I verified in the AWS console, it has created only 1 load balancer with service configuration. Ingress list:

 kubectl get ingress
NAME               HOSTS   ADDRESS   PORTS   AGE
sample-ingress     *                 80      19m
sample-ingress-1   *                 80      19m

Let me know if this helps.

like image 65
Shubham Singh Avatar answered Sep 02 '25 16:09

Shubham Singh