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 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:- kubectl -n ingress-nginx annotate ingressclasses nginx ingressclass.kubernetes.io/is-default-class="true"
复制代码 Verification
- kubectl get services -n ingress-nginx
复制代码 Get the of ingress-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: 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.- curl --location 'http://<external IP>:<ingress-nginx-node-port>' --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.
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |