nginx-ingress-controller部署配置详解

 更新时间:2023年11月22日 08:49:53   作者:moon  
这篇文章主要为大家介绍了nginx ingress controller的部署配置,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪

引言

  • 开源 Nginx Ingress Controller(k8s 官网推荐)、Nginx Incorporaton (nginx inc,nginx官网) 和 Nginx Incorporaton Plus
  • 当多个ingress对象资源配置同一个主机时,就会发生主机冲突。 Ingress Controller 支持两种处理主机冲突的选项:
  • Choosing the Winner

If multiple resources contend for the same host, the Ingress Controller will pick the winner based on the creationTimestamp of the resources: the oldest resource will win. In case there are more than one oldest resources (their creationTimestamp is the same), the Ingress Controller will choose the resource with the lexicographically smallest uid.

  • Merging Configuration for the Same Host

It is possible to merge configuration for multiple Ingress resources for the same host. One common use case for this approach is distributing resources across multiple namespaces.

  • 所以最好一个域名,对应一个ingress对象
# describe ingress 报错
  Warning  Rejected  17m (x2 over 6d23h)  nginx-ingress-controller  All hosts are taken by other resources
  Warning  Rejected  17m (x2 over 3d17h)  nginx-ingress-controller  All hosts are taken by other resources

一. 部署

wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.2.1/deploy/static/provider/cloud/deploy.yaml
# 选择版本
https://github.com/kubernetes/ingress-nginx/blob/controller-v1.4.0/deploy/static/provider/cloud/deploy.yaml
# 修改yaml中的image,改为自己的
    # 可用国内源: registry.cn-hangzhou.aliyuncs.com/google_containers/nginx-ingress-controller:v1.2.1
registry.cn-hangzhou.aliyuncs.com/google_containers/nginx-ingress-controller:v1.8.1
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-webhook-certgen:v20230407

二. 配置

1. 跨域

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: front-web
  namespace: web
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/enable-cors: "true"
    nginx.ingress.kubernetes.io/cors-allow-methods: "PUT, GET, POST, OPTIONS"
    nginx.ingress.kubernetes.io/cors-allow-headers: "Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control"
    nginx.ingress.kubernetes.io/cors-expose-headers: "*, X-CustomResponseHeader"
    nginx.ingress.kubernetes.io/cors-max-age: 600

2. 白名单

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-myapp
  namespace: default
  annotations:
    kubernetes.io/ingress.class: "nginx"
    # 白名单
    nginx.ingress.kubernetes.io/whitelist-source-range: 120.176.65.13,120.79.18.35
# 设置从代理服务器读取响应的超时时间(以秒为单位,默认值60)
nginx.ingress.kubernetes.io/proxy-read-timeout: "300"

# 强制重定向到 HTTPS(即使 Ingress 未启用 TLS)
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"

3. 强制https

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: test-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
    nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
    nginx.ingress.kubernetes.io/preserve-trailing-slash: "true"
spec:
  rules:
  - http:
      paths:
      - path: /testpath
        backend:
          serviceName: test
          servicePort: 80

4. 跳转

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: test-ingress
  namespace: uf
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  ingressClassName: nginx-ingress
  rules:
  - host: dev-gf.uf.net.cn
    http:
      paths:
      - backend:
          service:
            name: uf-epi-html
            port:
              number: 80
        path: /epi/(.*)
        pathType: ImplementationSpecific

以上就是nginx-ingress-controller部署配置详解的详细内容,更多关于nginx ingress controller部署配置的资料请关注脚本之家其它相关文章!

相关文章

  • Nginx 动态域名解析过程详解

    Nginx 动态域名解析过程详解

    这篇文章主要为大家介绍了Nginx 动态域名解析过程,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-03-03
  • 分享最新版 nginx内置变量 大全

    分享最新版 nginx内置变量 大全

    在配置基于nginx服务器的网站时,必然会用到 nginx内置变量 ,下面笔者将它整理成列表,把最新版本的变量列出来,以方便做配置时查询
    2016-04-04
  • Nginx中IF语句实现数学比较功能

    Nginx中IF语句实现数学比较功能

    这篇文章主要介绍了Nginx中IF语句实现数学比较功能,即在Nginx中用if判断数字大小,类似编程语言中的逻辑比较,需要的朋友可以参考下
    2015-02-02
  • 从Nginx切换到Tengine的步骤分享

    从Nginx切换到Tengine的步骤分享

    由淘宝网发起的Web服务器 Tengine 可以被看作一个更好的Nginx,或者是Nginx的超集。它在Nginx的基础上,针对大访问量网站的需求,添加了很多高级功能和特性
    2012-11-11
  • Nginx工作模式及代理配置的使用细节

    Nginx工作模式及代理配置的使用细节

    这篇文章主要为大家介绍了Nginx工作模式及代理配置的使用细节,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2022-03-03
  • 在Nginx服务器上安装配置博客程序Typecho的教程

    在Nginx服务器上安装配置博客程序Typecho的教程

    这篇文章主要介绍了在Nginx服务器上安装配置博客程序Typecho的教程,Typecho是一个开源的PHP博客程序,比WordPress更加轻量,需要的朋友可以参考下
    2015-12-12
  • nginx tcp负载均衡的具体实现

    nginx tcp负载均衡的具体实现

    Nginx是比较不错的开源Web服务器之一,它也可以用作TCP和UDP负载均衡器,本文主要介绍了nginx tcp负载均衡的具体实现,具有一定的参考价值,感兴趣的可以了解一下
    2024-05-05
  • Nginx实现基于请求头的访问控制配置的示例

    Nginx实现基于请求头的访问控制配置的示例

    在Nginx中,可以使用"allow"和"deny"指令来实现IP访问限制,本文给大家介绍Nginx实现基于请求头的访问控制配置,感兴趣的朋友一起看看吧
    2023-11-11
  • Nginx之QPS限制模块的具体使用

    Nginx之QPS限制模块的具体使用

    本文主要介绍了Nginx之QPS限制模块的具体使用,主要介绍Nginx QPS限制模块的原理、安装和使用方法,具有一定的参考价值,感兴趣的可以了解一下
    2023-09-09
  • 详解nginx 的 default_server 定义及匹配规则

    详解nginx 的 default_server 定义及匹配规则

    这篇文章主要介绍了详解nginx 的 default_server 定义及匹配规则,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-08-08

最新评论