Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

793
Visualizações
Kubernetes service : randomly getting Connection refused

When curl is made inside pod on port 80, response is fine. Calling curl outside container via Kubernetes service on machines IP and port 30803, sporadically "Connection refused" appears.

nginx app config:

server {
        listen  80;
        server_name 127.0.0.1;
        access_log  /var/log/nginx/access.log;
        error_log   /var/log/nginx/error.log;
        root        /usr/share/nginx/html;
        index index.html;

       error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

Kubernetes deployments and service manifest which is used:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-app
  namespace: dev
  labels:
    environment: dev
spec:
  selector:
      matchLabels:
         environment: dev
  replicas: 1
  template:
    metadata:
      labels:
        environment: dev
    spec:
      containers:
      - name: web-app
        imagePullPolicy: Never
        image: web-app:$BUILD_ID
        ports:
          - containerPort: 80
        readinessProbe:
          httpGet:
            path: /
            port: 80
          periodSeconds: 5
---
apiVersion: v1
kind: Service
metadata:
  name: web-app-dev-svc
  namespace: dev
  labels:
    environment: dev
spec:
  selector:
    environment: dev
  type: NodePort
  ports:
  - name: http
    nodePort: 30803
    port: 80
    protocol: TCP
    targetPort: 80

enter image description here

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

The issue was that 2 services in selector was using same label value - 'environment: dev' , and I assume this random connection was provoked, because it was balancing between one pod to another. Fixed labels values, now works perfectly.

over 4 years ago · Santiago Trujillo Relatório

0

When I run K8s with a NodePort, I don't have any problem. You can try first by using a proxy (port-forward) to your service and then your pod to ensure that all is working with the same behavior. If doing the port-forward to your pod directly works without any issue, then you might have an issue between your service and pod (e.g.: network policies such as too many calls in a short amount of time).

Regarding my nginx config, it's quite simple:

# /usr/share/nginx/html # cat /etc/nginx/conf.d/default.conf
server {
    listen       80;

    # Optional
    listen  [::]:80;
    server_name  localhost;

    # Default configuration
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;

        # Forward everything to the react router
        try_files $uri $uri/ /index.html?$args;
    }

    # If we wish some custom error page later, we could also add them.
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

Else, if you want to try with a verbatim nginx, simply use the nginx image (see kubernetes.io Cheat Sheet)

kubectl create deployment nginx --image=nginx
kubectl create services nodeport nginx-svc --tcp 30666:80 

# Nodeport should then be 30666 on the cluster
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda