Failed to replace NGINX NGINX Plus as reverse proxy for microservices on Google Cloud using Kubernetes
I am following this good tutorial on how to build a scalable API with microservices on Google Cloud using Kubernetes.
I have created 4 microservices and exposed the services that I am using NGINX Plus.
Note: The purpose of NGINX Plus / NGINX here is to act as a reverse proxy.
Below is the directory Structure:
-nginx
- Dockerfile
- deployment.yaml
- index.html
- nginx-repo.crt
- nginx-repo.key
- nginx.conf
- svc.yaml
Details of the files can be seen here . I am pasting the Dockerfile and nginx.conf here:
Dockerfile (original with 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 (Original with 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;
}
}
Everything seems to work fine with NGINX Plus and I can hit all 4 microservices with url for example. http: // xyzw / service [1 | 2 | 3 | 4] /? str = testnginx , where http: // xyzw is my external ip and NGINX takes care of routing requests internally. Now I am ready to do the same job without NGINX Plus using NGINX only.
Below are the updated files for NGINX:
Dockerfile (Updated for 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 (Updated for 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;
# }
#}
Basically, I removed the permission and server operators, which are NGINX Plus features and capable of generating a docker image, uploading it to google container and building my deployments and services, but getting 404 not found .
Am I missing something, or is this an NGINX limitation?
Please suggest anyone have any suggestion or previous experience with NGINX, Docker and Kubernets on Google Cloud.
source to share
No one has answered this question yet
See similar questions:
or similar: