NGINX安装和配置 [英] NGINX Installation and Configuration

查看:61
本文介绍了NGINX安装和配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Kubernetes的新手,并且想将NGINX Ingress Controller用于我当前正在研究的项目.我阅读了一些文档并观看了一些教程,但是我并没有真正理解以下内容:

  • 安装过程(我应该使用Helm,还是git repo ???)
  • 如何正确配置Ingress.例如,Kubernetes文档说使用nginx.conf文件(解决方案

答案:

我应该如何安装 nginx-ingress

没有一种正确的方法来安装 nginx-ingress .每种方式都有其自身的优缺点,每个Kubernetes集群可能需要不同的处理方式(例如:云托管的Kubernetes和minikube),您将需要确定最适合您的选项.

您可以从运行中选择:


我应该如何正确配置 Ingress ?

引用官方文档:

一个API对象,用于管理对集群中服务的外部访问,通常是HTTP.

- Kubernetes.io:文档:概念:服务网络:入口

基本上 Ingress 是一种资源,可告诉您的 Ingress控制器应该如何处理特定的 HTTP / HTTPS 流量

专门谈论 nginx-ingress ,将 HTTP / HTTPS 流量发送到的入口点是 Service名为 ingress-nginx-controller (位于 ingress-nginx 名称空间中)的类型为 LoadBalancer .在使用Kubernetes实现的Docker中,它将绑定到您计算机的本地主机.

  apiVersion:networking.k8s.io/v1种类:入口元数据:名称:极简主义规格:ingressClassName:"nginx"规则:-http:路径:- 小路:/pathType:前缀后端:服务:名称:nginx港口:数:80 

文档中经过修改的示例将告诉您的 Ingress 控制器将流量与任何 Host path:/(每一个<代码>路径)到端口 80 上名为 nginx 的服务.

应用后的上述配置将通过/etc/nginx/nginx.conf 文件中的 ingress-nginx 反映出来.

旁注!

在应用上述定义时,请查看 nginx.conf 部分的外观:

 位置/{设置$ namespace默认";将$ ingress_name设置为"minimal-inress";设置$ service_name"nginx";将$ service_port设置为"80";设置$ location_path"/";设置$ global_rate_limit_exceeding n; 

关于特定 Ingress 清单的外观应该看起来像您需要查阅要向其发送流量的软件的文档,并 Stackoverflow.com:问题:Ingin Nginx如何将资产存储到应用程序中

  • Stackoverflow.com:问题:我如何在本地访问nginx入口
  • I'm new to Kubernetes and wanted to use the NGINX Ingress Controller for the project I'm currently working on. I read some of the docs and watched some tutorials but I haven't really understood the:

    Does anybody know of a blog post or tutorial that makes these things clear. Out of everything I've learned so far (both frontend and backend) developing and deploying to a cloud environment has got me lost. I've been stuck on a problem for a week and want to figure out it Ingress can help me. Thanks!

    解决方案

    Answering:

    How should I install nginx-ingress

    There is no one correct way to install nginx-ingress. Each way has its own advantages/disadvantages, each Kubernetes cluster could require different treatment (for example: cloud managed Kubernetes and minikube) and you will need to determine which option is best suited for you.

    You can choose from running:

    • $ kubectl apply -f ...,
    • $ helm install ...,
    • terraform apply ... (helm provider),
    • etc.

    How should I properly configure Ingress?

    Citing the official documentation:

    An API object that manages external access to the services in a cluster, typically HTTP.

    -- Kubernetes.io: Docs: Concepts: Services networking: Ingress

    Basically Ingress is a resource that tells your Ingress controller how it should handle specific HTTP/HTTPS traffic.

    Speaking specifically about the nginx-ingress, it's entrypoint that your HTTP/HTTPS traffic should be sent to is a Service of type LoadBalancer named: ingress-nginx-controller (in a ingress-nginx namespace). In Docker with Kubernetes implementation it will bind to the localhost of your machine.

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: minimal-ingress
    spec:
      ingressClassName: "nginx"
      rules:
      - http:
          paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: nginx
                port:
                  number: 80
    

    The modified example from the documentation will tell your Ingress controller to pass the traffic with any Host and with path: / (every path) to a service named nginx on port 80.

    The above configuration after applying will be reflected by ingress-nginx in the /etc/nginx/nginx.conf file.

    A side note!

    Take a look on how the part of nginx.conf looks like when you apply above definition:

                    location / {
                           set $namespace      "default";
                           set $ingress_name   "minimal-ingress";
                           set $service_name   "nginx";
                           set $service_port   "80";
                           set $location_path  "/";
                           set $global_rate_limit_exceeding n;
    

    On how your specific Ingress manifest should look like you'll need to consult the documentation of the software that you are trying to send your traffic to and ingress-nginx docs.


    Addressing the part:

    how to properly configure the Ingress. For example, the Kubernetes docs say to use a nginx.conf file (https://kubernetes.io/docs/tasks/access-application-cluster/connecting-frontend-backend/#creating-the-frontend) which is never mentioned in the actual NGINX docs. They say to use ConfigMaps or annotations.

    You typically don't modify nginx.conf that the Ingress controller is using by yourself. You write an Ingress manifest and rest is taken by Ingress controller and Kubernetes. nginx.conf in the Pod responsible for routing (your Ingress controller) will reflect your Ingress manifests.

    Configmaps and Annotations can be used to modify/alter the configuration of your Ingress controller. With the Configmap you can say to enable gzip2 compression and with annotation you can say to use a specific rewrite.

    To make things clearer. The guide that is referenced here is a frontend Pod with nginx installed that passes the request to a backend. This example apart from using nginx and forwarding traffic is not connected with the actual Ingress. It will not acknowledge the Ingress resource and will not act accordingly to the manifest you've passed.

    A side note!

    Your traffic would be directed in a following manner (simplified):

    • Ingress controller -> frontend -> backend

    This example speaking from personal perspective is more of a guide how to connect frontend and backend and not about Ingress.


    Additional resources:

    The guide that I wrote some time ago should help you with the idea on how you can configure basic Ingress (it could be little outdated):

    这篇关于NGINX安装和配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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