Make sure pod ingress-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 should add the annotation ingressclass.kubernetes.io/is-default-class in your ingress class:
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: v1
kind: Pod
metadata:
name: nginx
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.18.0
---
apiVersion: v1
kind: Service
metadata:
name: nginx
spec:
ports:
- port: 80
targetPort: 80
selector:
app: nginx
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
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.
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.