我正在关注如何使用 Kubernetes 在 Google Cloud 上创建具有微服务的可扩展 API 的精彩教程。
我创建了 4 个微服务并公开了我正在使用 NGINX Plus 的服务。
注意: 这里 NGINX Plus / NGINX 的目的是作为反向代理。
下面是目录结构:
-nginx
--Dockerfile
--deployment.yaml
--index.html
--nginx-repo.crt
--nginx-repo.key
--nginx.conf
--svc.yaml
可以在此处查看文件的详细信息。我在这里粘贴 Docker 文件和 nginx.conf:
Dockerfile(NGINX Plus 原创):
FROM debian:8.3
RUN apt-get update && apt-get -y install wget
RUN mkdir -p /etc/ssl/nginx && wget -P /etc/ssl/nginx https://cs.nginx.com/static/files/CA.crt
COPY nginx-repo.key /etc/ssl/nginx/nginx-repo.key
COPY nginx-repo.crt /etc/ssl/nginx/nginx-repo.crt
RUN wget http://nginx.org/keys/nginx_signing.key && apt-key add nginx_signing.key
RUN apt-get -y install apt-transport-https libcurl3-gnutls lsb-release
RUN printf "deb https://plus-pkgs.nginx.com/debian `lsb_release -cs` nginx-plus\n" | tee /etc/apt/sources.list.d/nginx-plus.list
RUN wget -P /etc/apt/apt.conf.d https://cs.nginx.com/static/files/90nginx
RUN apt-get update && apt-get -y install nginx-plus
RUN mkdir /data
COPY index.html /data/index.html
COPY nginx.conf /etc/nginx/conf.d/backend.conf
RUN rm /etc/nginx/conf.d/default.conf
CMD ["nginx", "-g", "daemon off;"]
nginx.conf(NGINX Plus 原创):
resolver 10.11.240.10 valid=5s;
upstream reverse-backend {
zone reverse-backend 64k;
server reverse.default.svc.cluster.local resolve;
}
upstream arrayify-backend {
zone arrayify-backend 64k;
server arrayify.default.svc.cluster.local resolve;
}
upstream lower-backend {
zone lower-backend 64k;
server lower.default.svc.cluster.local resolve;
}
upstream upper-backend {
zone upper-backend 64k;
server upper.default.svc.cluster.local resolve;
}
server {
listen 80;
root /data;
location / {
index index.html index.htm;
}
status_zone backend-servers;
location /reverse/ {
proxy_pass http://reverse-backend/;
}
location /arrayify/ {
proxy_pass http://arrayify-backend/;
}
location /lower/ {
proxy_pass http://lower-backend/;
}
location /upper/ {
proxy_pass http://upper-backend/;
}
}
server {
listen 8080;
root /usr/share/nginx/html;
location = /status.html { }
location /status {
status;
}
}
NGINX Plus 似乎一切正常,我可以使用 url 访问所有 4 个微服务,例如。http://xyzw/service[1|2|3|4]/?str=testnginx,其中http://xyzw是我的外部 IP,NGINX 负责内部路由请求。现在我愿意在没有 NGINX Plus 的情况下只使用 NGINX 来做同样的工作。
以下是 NGINX 的更新文件:
Dockerfile(为 NGINX 更新):
FROM debian:8.3
RUN apt-get update && apt-get -y install wget
RUN mkdir -p /etc/ssl/nginx && wget -P /etc/ssl/nginx https://cs.nginx.com/static/files/CA.crt
#COPY nginx-repo.key /etc/ssl/nginx/nginx-repo.key
#COPY nginx-repo.crt /etc/ssl/nginx/nginx-repo.crt
#RUN wget http://nginx.org/keys/nginx_signing.key && apt-key add nginx_signing.key
RUN apt-get -y install apt-transport-https libcurl3-gnutls lsb-release
#RUN printf "deb https://plus-pkgs.nginx.com/debian `lsb_release -cs` nginx-plus\n" | tee /etc/apt/sources.list.d/nginx-plus.list
RUN wget -P /etc/apt/apt.conf.d https://cs.nginx.com/static/files/90nginx
RUN apt-get update && apt-get -y install nginx
RUN mkdir /data
COPY index.html /data/index.html
COPY nginx.conf /etc/nginx/conf.d/backend.conf
#RUN rm /etc/nginx/conf.d/default.conf
CMD ["nginx", "-g", "daemon off;"]
nginx.conf(为 NGINX 更新):
resolver 10.3.240.10 valid=5s;
upstream reverse-backend {
zone reverse-backend 64k;
server reverse.default.svc.cluster.local;
}
upstream arrayify-backend {
zone arrayify-backend 64k;
server arrayify.default.svc.cluster.local;
}
upstream lower-backend {
zone lower-backend 64k;
server lower.default.svc.cluster.local;
}
upstream upper-backend {
zone upper-backend 64k;
server upper.default.svc.cluster.local;
}
server {
listen 80;
root /data;
location / {
index index.html index.htm;
}
# status_zone backend-servers;
location /reverse/ {
proxy_pass http://reverse-backend/;
}
location /arrayify/ {
proxy_pass http://arrayify-backend/;
}
location /lower/ {
proxy_pass http://lower-backend/;
}
location /upper/ {
proxy_pass http://upper-backend/;
}
}
#server {
# listen 8080;
#
# root /usr/share/nginx/html;
#
# location = /status.html { }
#
# location /status {
# status;
# }
#}
基本上,我已经删除了解析和服务器语句,它们是 NGINX Plus 的功能并且能够创建 docker 映像,将其上传到谷歌容器并创建我的部署和服务,但得到404 not found。
我在这里遗漏了什么还是这是 NGINX 的限制?
如果有人对在 Google Cloud 上使用 NGINX、Docker 和 Kubernetes 有任何建议或先前的经验,请提出建议。