NGINX安装和配置 [英] NGINX Installation and Configuration
问题描述
我是Kubernetes的新手,并且想将NGINX Ingress Controller用于我当前正在研究的项目.我阅读了一些文档并观看了一些教程,但是我并没有真正理解以下内容:
- 安装过程(我应该使用Helm,还是git repo ???)
- 如何正确配置Ingress.例如,Kubernetes文档说使用nginx.conf文件(解决方案
答案:
我应该如何安装
nginx-ingress
没有一种正确的方法来安装 nginx-ingress
.每种方式都有其自身的优缺点,每个Kubernetes集群可能需要不同的处理方式(例如:云托管的Kubernetes和minikube),您将需要确定最适合您的选项.
您可以从运行中选择:
-
$ kubectl apply -f ...
, -
$ helm install ...
, -
terraform apply ...
(帮助提供商), - 等
我应该如何正确配置
Ingress
?
引用官方文档:
一个API对象,用于管理对集群中服务的外部访问,通常是HTTP.
基本上 Ingress
是一种资源,可告诉您的 Ingress控制器
应该如何处理特定的 HTTP
/ HTTPS
流量
专门谈论 nginx-ingress
,将 HTTP
/ HTTPS
流量发送到的入口点是 Service名为
.在使用Kubernetes实现的Docker中,它将绑定到您计算机的本地主机. ingress-nginx-controller
(位于 ingress-nginx
名称空间中)的类型为 LoadBalancer
的
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
清单的外观应该看起来像您需要查阅要向其发送流量的软件的文档,并 https://kubernetes.io/docs/tasks/access-application-cluster/connecting-frontend-backend/#creating-the-frontend ),在实际中从未提及NGINX文档.他们说要使用ConfigMap或注释.
您通常不会自己修改 Ingress控制器
所使用的 nginx.conf
.您编写一个 Ingress
清单,其余部分由 Ingress控制器
和 Kubernetes
占用.在 Pod
中负责路由的 nginx.conf
(您的 Ingress控制器
)将反映您的 Ingress
清单.>
Configmaps
和 Annotations
可用于修改/更改您的 Ingress控制器
的配置.使用 Configmap
,您可以说启用 gzip2
压缩;使用注释,您可以说使用特定的 rewrite
.
使事情更清晰.此处引用的指南是安装了 nginx
的前端 Pod
,该请求将请求传递到 backend
.除了使用 nginx
和转发流量外,该示例未与实际的 Ingress
连接.它不会确认 Ingress
资源,并且不会对您传递的清单做出相应的反应.
旁注!
您的流量将通过以下方式(简化)定向:
入口控制器
->前端
->后端
此示例从个人角度来讲,它更多地是指导如何连接前端
和后端
,而不是有关 Ingress 代码>.
其他资源:
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:
- installation process (should I use Helm, the git repo???)
- 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
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:
- Stackoverflow.com: Questions: Ingress nginx how sto serve assets to application
- Stackoverflow.com: Questions: How nginx ingress controller backend protocol annotation works
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屋!