'How to assign IP address to nginx Ingress resource in k8s?

I want to install nginx-controller in my Kubernetes cluster. I setup my master node at one server, and worker node at another server. I am using Ubuntu 20.04.

I followed the link (https://github.com/kubernetes/ingress-nginx/blob/main/deploy/static/provider/cloud/1.23/deploy.yaml) and use 'kubectl apply -f file_name.yaml' to install the controller.

The controller pod is running:

NAME                                       READY   STATUS    RESTARTS   AGE
ingress-nginx-controller-c57bb9674-p2z9d   1/1     Running   0          70s

Now I want to create an Ingress resource. I used this yaml file:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-hello
  namespace: ingress-nginx
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
    - http:
        paths:
        - path: /hello
          pathType: Exact
          backend:
            service:
              name: ingress-hello
              port:
                number: 80

However, when I applied this yaml file, and use 'kubectl get ingress -n ingress-nginx', I saw:

NAME            CLASS    HOSTS   ADDRESS   PORTS   AGE
ingress-hello   <none>   *                 80      24s

I noticed that the address for this Ingress resource is empty.

I am just wondering is it possible to assign an IP address to it? Any method/ setting to assign the address?

Thanks.



Solution 1:[1]

You can access to your service by http://localhost:80/hello, and if you wanan specify a custom host you need to modify your ingnx file.

This is an example:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-hello
  namespace: ingress-nginx
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
    - host: your_host  
      http:
        paths:
        - path: /hello
          pathType: Exact
          backend:
            service:
              name: ingress-hello
              port:
                number: 80

and you need to open your hosts files in your /system32/etc/hosts directory and add your customized host, and then your service will be accessible through http://your_host:80/hello

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Aladin