Is it possible to dynamically add hosts to ingress with Kubernetes?

kubernetes ingress annotations
kubernetes ingress multiple hosts
kubernetes ingress https
kubernetes ingress http2
kubernetes ingress tutorial
kubectl get ingress controller
kubectl delete ingress
best ingress controller for kubernetes

If you are managing ingress service such as in the following example, instead of updating the ingress file below, is there a means of adding an additional host/service such as echo3.example.com with out needing to apply an updated version of the original file?

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: echo-ingress
spec:
  rules:
  - host: echo1.example.com
    http:
      paths:
      - backend:
          serviceName: echo1
          servicePort: 80
  - host: echo2.example.com
    http:
      paths:
      - backend:
          serviceName: echo2
          servicePort: 80

# NEW HOST/SERVICE

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: echo-ingress
spec:
  rules:
  - host: echo3.example.com ### <= `echo3` addeded
    http:
      paths:
      - backend:
          serviceName: echo3
          servicePort: 80

Is there a way of applying this new host without needing to extend the old file?

If you apply the two files, the second one will overwrite the first one as they have the same name. So, you would need to edit the original every time you add a new rule.

One possible solution to avoid this problem would be to use Contour. In that case you could keep each IngressRoute in a separate resource and avoid conflicts like that.

In your case, you would have something like:

# ingressroute-echo1.yaml
apiVersion: contour.heptio.com/v1beta1
kind: IngressRoute
metadata:
  name: echo-ingress-1
spec:
  virtualhost:
    fqdn: echo1.example.com
  routes:
    - match: /
      services:
        - name: echo1
          port: 80

# ingressroute-echo2.yaml
apiVersion: contour.heptio.com/v1beta1
kind: IngressRoute
metadata:
  name: echo-ingress-2
spec:
  virtualhost:
    fqdn: echo2.example.com
  routes:
    - match: /
      services:
        - name: echo2
          port: 80

# ingressroute-echo3.yaml
apiVersion: contour.heptio.com/v1beta1
kind: IngressRoute
metadata:
  name: echo-ingress-3
spec:
  virtualhost:
    fqdn: echo3.example.com
  routes:
    - match: /
      services:
        - name: echo3
          port: 80

Dynamic Ingress in Kubernetes, A mapping object is created with a prefix of /httpbin/ and a service name of httpbin.org. The host_rewrite annotation specifies that the HTTP host  Kubernetes makes it easy to deploy applications that consist of many microservices, but one of the key challenges with this type of architecture is dynamically routing ingress traffic to each of these services. One approach is Ambassador, a Kubernetes-native open source API Gateway built on the Envoy Proxy.

I mean you can just make it a separate Ingress object/file, no need for it to be in the same one. Or you can use something like Kustomize.

Ingress, Ingress may provide load balancing, SSL termination and If you create it using kubectl apply -f you should be able to view the state of the sessions, dynamic weights) are not yet exposed through the Ingress. To update an existing Ingress to add a new Host, you can update it by editing the resource:. As far as I can tell right now it's only possible to create an ingress to address services inside the namespace in which the Ingress resides. It would be good to be able to address services in any namespace.

You can make different ingress object with different annotation also.Make to two files of ingress with hosts and services.

Adding entries to Pod /etc/hosts with HostAliases, Adding entries to a Pod's /etc/hosts file provides Pod-level override of hostname resolution when DNS and other options are not applicable. Ingress resource only supports rules for directing HTTP traffic. Ingress rules. Each http rule contains the following information: An optional host. In this example, no host is specified, so the rule applies to all inbound HTTP traffic through the IP address specified. If a host is provided (for example, foo.bar.com), the rules apply to that host.

Set up Ingress on Minikube with the NGINX Ingress , An Ingress controller fulfills the rules set in the Ingress. This page shows Add the following line to the bottom of the /etc/hosts file. Note: If you  I was recently adding e2e test cases to Kubernetes Ingress-Nginx when I realized that there aren’t too many resources out there to show how to properly configure and test Mutual(Client

Improvements to the Ingress API in Kubernetes 1.18, ways to manage inbound network traffic to Kubernetes workloads. pathType field that can specify how Ingress paths should be matched. to Make Kubernetes Production Grade Anywhere · Dynamically Expand Wildcard matches require the http host header is equal to the suffix of the wildcard rule. You can add these custom entries with the HostAliases field in PodSpec. Modification not using HostAliases is not suggested because the file is managed by the kubelet and can be overwritten on during Pod creation/restart. Default hosts file content Start an Nginx Pod which is assigned a Pod IP:

Ingress Controllers, In order for the Ingress resource to work, the cluster must have an ingress controller running. Unlike other types of controllers which run as part  Outside of Kubernetes, I might use a script to manage /etc/hosts and expect nothing else to change the file; while it is possible that I use an init container to do the same modification to /etc/hosts, since the mounting of /etc/hosts happens whenever a container is restarted, I risk the file being changed and my application not being able to

Comments
  • Possible duplicate of Dynamically adding/removing named hosts from k8s ingress
  • @t-prisar Thanks, I had a look there, The question is a duplicate but the answers are very different, this one says it is possible, while the linked one disagrees?
  • Thanks, I should have seen that the name being different wouldn't overwrite the file initial config.