Connection Refused with nginx and kubernetes

3/26/2019

I trying to deploy my angular application with kubernates inside a container with nginx.

I create my docker file:

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;"]

My nginx config:

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;
  }

}

If I launch this image locally It works perfectly but when I deploy this container inside a kubernate cluster the site load fine but all api request shows the error ERR_CONNECTION_REFUSED.

I'm trying to deploy in GCP I build the image and then publish my image by GCP dashboard.

Some idea for this ERR_CONNECTION_REFUSED?

-- Brunno
google-cloud-platform
kubernetes
nginx

3 Answers

3/31/2019

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.

-- Brunno
Source: StackOverflow

4/3/2019

Good that you have figured out the issue. But, Did you try using the service_names instead of the Pod IPs? It is suggested method(https://kubernetes.io/docs/tasks/administer-cluster/access-cluster-services/#manually-constructing-apiserver-proxy-urls) of accessing services by their names within the Kubernetes cluster and with NodeIP or LoadBalancerIP outside the cluster.

-- ravi kiran mahankali
Source: StackOverflow

3/26/2019

Kubernetes Engine nodes are provisioned as instances in Compute Engine. As such, they adhere to the same stateful firewall mechanism as other instances. Have you configured the firewall rules?

https://cloud.google.com/solutions/prep-kubernetes-engine-for-prod#firewalling

-- afed
Source: StackOverflow