Search code examples
kubernetesgoogle-cloud-platformnginx-ingress

Is it possible to attach multiple ingress resources to an Application Pod in kubernetes?


I have a NGINX Ingress controller and multiple ingress resources attached to each pod in GKE. I want to know if I can attach more than one ingress resource to a single pod.

For example I have a Java application running on a pod and I have attached an ingress resource to it. The application can be accessed at example.dev.com and it already has a ssl cert attached to it which I don't want to touch. I want the same application to be accessed via example.com by attaching a new Ingress resource and applying a new SSL certificate and hostname example.com . Is it possible ? Any leads will be appreciated.


Solution

  • Yes you can do it.

    For example I have a Java application running on a pod and I have attached an ingress resource to it. The application can be accessed at example.dev.com and it already has a ssl cert attached to it which I don't want to touch. I want the same application to be accessed via example.com by attaching a new Ingress resource and applying a new SSL certificate and hostname example.com . Is it possible ? Any leads will be appreciated.

    Create another ingress with an SSL cert stored into the secret and attach that secret to the new ingress.

    make sure you are providing different names in the new ingress so it won't overwrite the existing one.

    You can keep both config inside single file or else make different ingress

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: ingress-wildcard-host
    spec:
      tls:
      - hosts:
          - example.com
          - example.dev.com
        secretName: testsecret-tls
      rules:
      - host: "example.dev.com"
        http:
          paths:
          - pathType: Prefix
            path: "/bar"
            backend:
              service:
                name: service1
                port:
                  number: 80
      - host: "example.com"
        http:
          paths:
          - pathType: Prefix
            path: "/foo"
            backend:
              service:
                name: service1
                port:
                  number: 80
    

    If you have a single wild card SSL

    tls:
      - hosts:
          - example.dev.com
          - example.com
        secretName: testsecret-tls
    

    If you don't want both together just create once ingress for example.com as you want

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: example-ingress
    spec:
      tls:
      - hosts:
          - example.com
        secretName: testsecret-tls
      rules:
      - host: example.com
        http:
          paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: service1
                port:
                  number: 80
    

    Ref :https://kubernetes.io/docs/concepts/services-networking/ingress/