Installation

Use the compatible version with your Kubernetes cluster, otherwise, you may get some unexpected exception or error.

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.3/deploy/static/provider/baremetal/deploy.yaml

Make sure podingress-nginx-controller-xxxx is running, otherwise using ‘kubectl -n ingress-nginx get ingressclasses‘ and check the ‘Event’ part.

This YAML will create a new namespace ‘ingress-nginx’ for Nginx, and an Ingress Class object ‘nginx’ will be created too by default, you could check from Kubernetes dashboard or the CLI below

kubectl get ingressclasses -n ingress-nginx

If this is only instance of the Ingresss-NGINX controller, you shouldadd the annotationingressclass.kubernetes.io/is-default-classin your ingress class:

kubectl -n ingress-nginx annotate ingressclasses nginx ingressclass.kubernetes.io/is-default-class="true"

Verification

kubectl get services -n ingress-nginx

Get the ofingress-nginx-controller

Get node with the following command

kubectl get nodes -o wide

Access http://: in the browser, and you will get”404 Not Found” from nginx, no worry, that is because no backend service configured yet. If you are using docker desktop kubenetes, the will be localhost.

Now we deploy a nginx service with the following YAML to test the ingress controller,

apiVersion: v1kind: Podmetadata:  name: nginx  labels:    app: nginxspec:  containers:    - name: nginx      image: nginx:1.18.0---apiVersion: v1kind: Servicemetadata:  name: nginxspec:  ports:    - port: 80      targetPort: 80  selector:    app: nginx---apiVersion: networking.k8s.io/v1kind: Ingressmetadata:  name: example.com  annotations:    nginx.ingress.kubernetes.io/rewrite-target: /spec:  ingressClassName: nginx  rules:    - host: nginx.example.com      http:        paths:          - path: /            pathType: Prefix            backend:              service:                name: nginx                port:                   number: 80

Use the following command to check the availability.

curl --location 'http://:' --header 'Host: nginx.example.com'

If you aren’t familiar with curl, you can use Postmen, it; ‘s more straightforward. If you want to verify in a browser, for example, chrome, then you need to use some plugin like ModHeader to provide the header parameter.