连接被Nginx和kubernetes拒绝

Bru*_*nno 3 nginx google-cloud-platform kubernetes

我试图在带有Nginx的容器内使用kubernates部署我的angular应用程序。

我创建了我的docker文件:

FROM node:10-alpine as builder

COPY package.json package-lock.json ./

RUN npm ci && mkdir /ng-app && mv ./node_modules ./ng-app

WORKDIR /ng-app

COPY . .

RUN npm run ng build -- --prod --output-path=dist

FROM nginx:1.14.1-alpine

COPY nginx/default.conf /etc/nginx/conf.d/

RUN rm -rf /usr/share/nginx/html/*

COPY --from=builder /ng-app/dist /usr/share/nginx/html

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]
Run Code Online (Sandbox Code Playgroud)

我的nginx配置:

server {

  listen 80;

  sendfile on;

  default_type application/octet-stream;


  gzip on;
  gzip_http_version 1.1;
  gzip_disable      "MSIE [1-6]\.";
  gzip_min_length   1100;
  gzip_vary         on;
  gzip_proxied      expired no-cache no-store private auth;
  gzip_types        text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
  gzip_comp_level   9;


  root /usr/share/nginx/html;

  location / {
    try_files $uri $uri/ /index.html =404;
  }

  location /api {
    proxy_pass https://my-api;
  }

}
Run Code Online (Sandbox Code Playgroud)

如果我在本地启动此映像,则效果很好,但是当我在kubernate集群中部署此容器时,站点加载正常,但所有api请求均显示错误ERR_CONNECTION_REFUSED

我试图在GCP中进行部署,然后构建映像,然后通过GCP仪表板发布映像。

有什么想法ERR_CONNECTION_REFUSED吗?

Bru*_*nno 5

I found the solution. The problem was with my requests, I was using localhost on URL with that I took the wrong pod IP now I change the request to use direct the Service IP and it sort of my problem.