如何将Nginx配置转换为Nginx-ingress? [英] How to convert Nginx configuration to nginx-ingress?

查看:64
本文介绍了如何将Nginx配置转换为Nginx-ingress?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的nginx具有以下配置:

I have nginx with following configuration:

  proxy_redirect off;
  proxy_set_header Host $host;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header X-Forwarded-Proto $scheme;
  client_max_body_size 1g;
  client_body_buffer_size 128k;
  proxy_connect_timeout 120;
  proxy_send_timeout 240;
  proxy_read_timeout 240;
  proxy_buffers 32 4k;

  proxy_hide_header Strict-Transport-Security;
  proxy_hide_header Content-Type;
  add_header Content-Type application/json;

我想将我的Nginx配置转换为kubernetes ingress-nginx(入口资源).有没有一种使用kubernetes Ingress资源来实现此配置的方法?在阅读ingress-nginx文档时,我还没有找到如何将proxy_pass或多个重写映射到Ingress资源的方法.我希望参考一些具有类似配置的详细文档或示例.

I would like to translate my nginx config to kubernetes ingress-nginx (Ingress resource). Is there a way to implement this config using kubernetes Ingress resources? Reading ingress-nginx docs I haven't found how to map proxy_pass or multiple rewrites to Ingress resource. I would appreciate ref to some detailed doc or sample with similar config.

推荐答案

是的,可以使用片段和自定义模板来实现,如

Yes can do it using Snippets and Custom Templates as explained here in NGINX Ingress Controller documentation by nginxinc.

通过ConfigMap使用代码段的示例:

Example of using Snippets via ConfigMap:

---
# Source: nginx-ingress/templates/controller-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-config
  labels:
    app.kubernetes.io/name: nginx-ingress
    helm.sh/chart: nginx-ingress-0.3.4
    app.kubernetes.io/managed-by: Tiller
    app.kubernetes.io/instance: RELEASE-NAME
data:
   server-snippets: |
    location /helloworld {
      proxy_redirect off;
      proxy_http_version 1.1;
    }

这篇关于如何将Nginx配置转换为Nginx-ingress?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆