在 kubernetes 中使用 nginx ingress 时是否需要 nginx 镜像?
Do I need nginx image when i use nginx ingress in kubernetes?
我正在学习kubernetes并且陷入了一个我很困惑的地步。我已经在 pod 中安装了 metallb 和 ingress-nginx so it is possible to access content from outside. I saw several examples that are using nginx image 运行ning,尽管它们也在使用 ingress-nginx。
难道 ingress-nginx 不能像 nginx 镜像一样完成所有工作吗?否则那两个扮演什么角色?
我需要在我想利用一些 nginx 功能(如 gzip)的地方部署 express 服务器,因此它是反向代理的来源。
所以我需要让它在 ingress-nginx 级别或从 nginx 图像运行吗?如果我需要 nginx 图像,这是否意味着我需要 运行 使用我的 express 应用程序分别 运行 nginx 图像和我构建的节点图像?
简答:否
但是很复杂。
nginx
image 你提到的是最受欢迎的图像之一(在撰写本文时 Docker Hub 上的第 5 个),相对较小 (133MB),并且很容易记住。这就是为什么它在许多教程中被广泛用作示例的原因。
Isn't ingress-nginx capable to do all work as nginx image?
某种程度上。
Pod 和 Ingress 是不同的 Kubernetes 资源,它们的行为也不同。 nginx
镜像通常部署为 pod 中的容器。
在 nginx ingress controller 的情况下,Pod 和 Ingress[=58= 都使用相似的图像](下文提到)。
每当您在入口控制器中部署(例如)重写规则时
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
正在 nginx-ingress
图像中的 nginx.conf
文件中创建相应的条目(同样,在下面提到)。
你可以阅读更多here。
也就是说,当您创建 Ingress Controller 资源时,有 nginx/nginx-ingress
映像正在部署。
您甚至可以从 Docker Hub
中提取它
$ docker image pull nginx; docker image pull nginx/nginx-ingress
Using default tag: latest
latest: Pulling from library/nginx
69692152171a: Pull complete
30afc0b18f67: Pull complete
596b1d696923: Pull complete
febe5bd23e98: Pull complete
8283eee92e2f: Pull complete
351ad75a6cfa: Pull complete
Digest: sha256:6d75c99af15565a301e48297fa2d121e15d80ad526f8369c526324f0f7ccb750
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
Using default tag: latest
latest: Pulling from nginx/nginx-ingress
69692152171a: Already exists
30afc0b18f67: Already exists
596b1d696923: Already exists
febe5bd23e98: Already exists
8283eee92e2f: Already exists
351ad75a6cfa: Already exists
ff0027f23312: Pull complete
18361787d4a4: Pull complete
e1aba8353cbb: Pull complete
f9a4438768c4: Pull complete
Digest: sha256:a57fc7835c14b7294180f5c11ae6b81f2745189ef2adb57a5188952bf8aaa17a
Status: Downloaded newer image for nginx/nginx-ingress:latest
docker.io/nginx/nginx-ingress:latest
$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx/nginx-ingress latest 1bc8d3e90493 2 weeks ago 177MB
nginx latest d1a364dc548d 2 weeks ago 133MB
如您所见,nginx
和 nginx-ingress
是两个不同的图像。
事实上,您甚至可以 build the image 自己。
我正在学习kubernetes并且陷入了一个我很困惑的地步。我已经在 pod 中安装了 metallb 和 ingress-nginx so it is possible to access content from outside. I saw several examples that are using nginx image 运行ning,尽管它们也在使用 ingress-nginx。
难道 ingress-nginx 不能像 nginx 镜像一样完成所有工作吗?否则那两个扮演什么角色?
我需要在我想利用一些 nginx 功能(如 gzip)的地方部署 express 服务器,因此它是反向代理的来源。
所以我需要让它在 ingress-nginx 级别或从 nginx 图像运行吗?如果我需要 nginx 图像,这是否意味着我需要 运行 使用我的 express 应用程序分别 运行 nginx 图像和我构建的节点图像?
简答:否
但是很复杂。
nginx
image 你提到的是最受欢迎的图像之一(在撰写本文时 Docker Hub 上的第 5 个),相对较小 (133MB),并且很容易记住。这就是为什么它在许多教程中被广泛用作示例的原因。
Isn't ingress-nginx capable to do all work as nginx image?
某种程度上。
Pod 和 Ingress 是不同的 Kubernetes 资源,它们的行为也不同。 nginx
镜像通常部署为 pod 中的容器。
在 nginx ingress controller 的情况下,Pod 和 Ingress[=58= 都使用相似的图像](下文提到)。
每当您在入口控制器中部署(例如)重写规则时
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
正在 nginx-ingress
图像中的 nginx.conf
文件中创建相应的条目(同样,在下面提到)。
你可以阅读更多here。
也就是说,当您创建 Ingress Controller 资源时,有 nginx/nginx-ingress
映像正在部署。
您甚至可以从 Docker Hub
$ docker image pull nginx; docker image pull nginx/nginx-ingress
Using default tag: latest
latest: Pulling from library/nginx
69692152171a: Pull complete
30afc0b18f67: Pull complete
596b1d696923: Pull complete
febe5bd23e98: Pull complete
8283eee92e2f: Pull complete
351ad75a6cfa: Pull complete
Digest: sha256:6d75c99af15565a301e48297fa2d121e15d80ad526f8369c526324f0f7ccb750
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
Using default tag: latest
latest: Pulling from nginx/nginx-ingress
69692152171a: Already exists
30afc0b18f67: Already exists
596b1d696923: Already exists
febe5bd23e98: Already exists
8283eee92e2f: Already exists
351ad75a6cfa: Already exists
ff0027f23312: Pull complete
18361787d4a4: Pull complete
e1aba8353cbb: Pull complete
f9a4438768c4: Pull complete
Digest: sha256:a57fc7835c14b7294180f5c11ae6b81f2745189ef2adb57a5188952bf8aaa17a
Status: Downloaded newer image for nginx/nginx-ingress:latest
docker.io/nginx/nginx-ingress:latest
$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx/nginx-ingress latest 1bc8d3e90493 2 weeks ago 177MB
nginx latest d1a364dc548d 2 weeks ago 133MB
如您所见,nginx
和 nginx-ingress
是两个不同的图像。
事实上,您甚至可以 build the image 自己。