Home > database >  How to configure nginx ingress rules without "host"
How to configure nginx ingress rules without "host"

Time:12-23

I have installed nginx ingress in kubernetes from official documenation. But while configuring the rules without mentioning the "host". I am getting the below erros.

error spec.rules[0].host: Required value

Is it possible to configure it without host as I want to access it using only IP address

and I also found the below deployment file with which I am able to apply rules without "host". But not sure is this is safe to use. Please guide me here

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.44.0/deploy/static/provider/cloud/deploy.yaml

CodePudding user response:

Do you mean to configure the ingress? The ingress controller is different from ingress itself. If you are configuring ingress, then host is completely optional. If host is omitted, all the http traffic is directed through IP address by default. Refer to this documentation for more info https://kubernetes.io/docs/concepts/services-networking/ingress/

CodePudding user response:

It worked with ingress-nginx, as the kubernetes ingress documentation makes abundantly clear that the host is not required.

Because instances of the ingress nginx controller actually run on nodes in your cluster, nginx Ingresses will only receive static IP addresses by default if your cloud provider allows for the assignment of static IP addresses to nodes. On GKE/GCE, for instance, nodes receive static IP addresses, but upgrades do not keep those IP addresses.

Simply place the ingress-nginx-controller behind a Service of Type=LoadBalancer to obtain a static IP address.

Create a loadbalancer service first, and then wait for it to get an IP:

$ kubectl create -f static-ip-svc.yaml service "ingress-nginx-lb" created

$ kubectl get svc ingress-nginx-lb NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE ingress-nginx-lb 10.0.138.113 104.154.109.191 80:31457/TCP,443:32240/TCP 15m

Then, pass the --publish-service flag to the ingress controller to change it to use the Service's static IP (the example yaml used in the next step already has it set to "ingress-nginx-lb").

 $ kubectl create -f ingress-nginx-controller.yaml
    deployment "ingress-nginx-controller" created

The IP that was allocated in the previous step will now be available to each Ingress that is created using the nginx ingress.class annotation.

$ kubectl create -f ingress-nginx.yaml
ingress "ingress-nginx" created

$ kubectl get ing ingress-nginx
NAME            HOSTS     ADDRESS           PORTS     AGE
ingress-nginx   *         104.154.109.191   80, 443   13m

$ curl 104.154.109.191 -kL
CLIENT VALUES:
client_address=10.180.1.25
command=GET
real path=/
query=nil
request_version=1.1
request_uri=http://104.154.109.191:8080/

This is clearly explained in how to use the Ingress-NGINX controller to give an Ingress a static IP address Refer this for more information

There is a similar query addresed in this Stack link

If you want to use a static ip in kubernetes ingress configuration, you need to use load balancer which can be easily done in any of the cloud providers. I.e GCP,AWS—-etc

  • Related