Nginx Ingress

兜兜零元  金牌会员 | 2024-3-2 18:41:35 | 来自手机 | 显示全部楼层 | 阅读模式
打印 上一主题 下一主题

主题 598|帖子 598|积分 1794

Installation

Use the compatible version with your Kubernetes cluster, otherwise, you may get some unexpected exception or error.
  1. 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
  1. 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:
  1. kubectl -n ingress-nginx annotate ingressclasses nginx ingressclass.kubernetes.io/is-default-class="true"
复制代码
Verification
  1. kubectl get services -n ingress-nginx
复制代码
Get the  of ingress-nginx-controller

Get node  with the following command
  1. 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,
  1. apiVersion: v1
  2. kind: Pod
  3. metadata:
  4.   name: nginx
  5.   labels:
  6.     app: nginx
  7. spec:
  8.   containers:
  9.     - name: nginx
  10.       image: nginx:1.18.0
  11. ---
  12. apiVersion: v1
  13. kind: Service
  14. metadata:
  15.   name: nginx
  16. spec:
  17.   ports:
  18.     - port: 80
  19.       targetPort: 80
  20.   selector:
  21.     app: nginx
  22. ---
  23. apiVersion: networking.k8s.io/v1
  24. kind: Ingress
  25. metadata:
  26.   name: example.com
  27.   annotations:
  28.     nginx.ingress.kubernetes.io/rewrite-target: /
  29. spec:
  30.   ingressClassName: nginx
  31.   rules:
  32.     - host: nginx.example.com
  33.       http:
  34.         paths:
  35.           - path: /
  36.             pathType: Prefix
  37.             backend:
  38.               service:
  39.                 name: nginx
  40.                 port:
  41.                   number: 80
复制代码
 Use the following command to check the availability.
  1. 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. 

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

兜兜零元

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表