无法使用 NGINX Plus 替换 NGINX 作为使用 Kubernetes 的 Google Cloud 上微服务的反向代理

2024-04-09

我正在关注this https://cloudplatform.googleblog.com/2016/06/creating-a-scalable-API-with-microservices.html关于如何使用 Kubernetes 在 Google Cloud 上创建具有微服务的可扩展 API 的精彩教程。

我创建了 4 个微服务并公开我正在使用 NGINX Plus 的服务。

Note : NGINX Plus / NGINX 的目的是作为反向代理。

以下是目录结构:

-nginx

--Dockerfile

--部署.yaml

--index.html

--nginx-repo.crt

--nginx-repo.key

--nginx.conf

--svc.yaml

可以看到文件的详细信息here https://github.com/thesandlord/nginx-kubernetes-lb/tree/master/nginx。我将 Dockerfile 和 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://x.y.z.w/service[1|2|3|4]/?str=testnginx http://x.y.z.w/service%5B1%7C2%7C3%7C4%5D/?str=testnginx, 在哪里http://x.y.z.w http://x.y.z.w是我的外部 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 映像,将其上传到 google 容器并创建我的部署和服务,但得到404 未找到 https://drive.google.com/file/d/0B1avLHdER_1IcDFMR2luWGE3bzg/view?usp=sharing.

我在这里遗漏了一些东西还是这是 NGINX 的限制?

如果有人有任何在 Google Cloud 上使用 NGINX、Docker 和 Kubernetes 的建议或经验,请提出建议。


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法使用 NGINX Plus 替换 NGINX 作为使用 Kubernetes 的 Google Cloud 上微服务的反向代理 的相关文章

随机推荐