Kubernetes shows multiple requests instead of one

8/10/2021

Im using Kubenetes kubectl Client Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.2" And i have a website that runs on python pod + nginx pod.

for some reason if i reload site i can see it sends to pod 3 requests instead of 1 ,why does it happened?

I converted my env from docker-compose to kub , in my docker-compose i didnt have this issue.

nginx-service.yaml:

apiVersion: v1
kind: Service
metadata:
  annotations:
    kompose.cmd: /snap/kompose/19/kompose-linux-amd64 convert --volumes hostPath
    kompose.version: 1.21.0 (992df58d8)
  creationTimestamp: null
  labels:
    io.kompose.service: nginx
  name: nginx
spec:
  ports:
  - name: "8443"
    port: 8443
    targetPort: 80
  externalIPs:
      - 10.10.10.13

  selector:
    io.kompose.service: nginx
status:
  loadBalancer: {}

api service looks the same on port 5001

I can see both in nginx and api pod log the same request 2-3X times.

log:

1628596046 [10], INF, Authentication ('Got New authentication request:', 'USER', 'ADMIN22')
1628596046 [10], INF, Authentication ('Got New authentication request:', 'USER', 'ADMIN22')
1628596046 [10], INF, Authentication ('Got New authentication request:', 'USER', 'ADMIN22')
1628596046 [10], INF, activeSessions ('Checking for active sessions...',)
1628596046 [10], INF, activeSessions ('Checking for active sessions...',)
1628596046 [10], INF, activeSessions ('Checking for active sessions...',)
1628596046 [10], INF, activeSessions ({},)
1628596046 [10], INF, activeSessions ({},)
1628596046 [10], INF, activeSessions ({},)
10.244.0.220 - - [10/Aug/2021 11:47:26] "GET /Authentication?token=9FB4FB18BCB182938263179252956219A4FAE2256D78D5E17E654CED9C6FB6BF HTTP/1.1" 200 -
10.244.0.220 - - [10/Aug/2021 11:47:26] "GET /Authentication?token=9FB4FB18BCB182938263179252956219A4FAE2256D78D5E17E654CED9C6FB6BF HTTP/1.1" 200 -
10.244.0.220 - - [10/Aug/2021 11:47:26] "GET /Authentication?token=9FB4FB18BCB182938263179252956219A4FAE2256D78D5E17E654CED9C6FB6BF HTTP/1.1" 200 -

any ides? Thanks

================================ API service and pod YAML :

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: /snap/kompose/19/kompose-linux-amd64 convert --volumes hostPath
    kompose.version: 1.21.0 (992df58d8)
  creationTimestamp: null
  labels:
    io.kompose.service: api
  name: api
spec:
  replicas: 1
  selector:
    matchLabels:
      io.kompose.service: api
  strategy:
    type: Recreate
  template:
    spec:
      hostNetwork: true
    metadata:
      annotations:
        kompose.cmd: /snap/kompose/19/kompose-linux-amd64 convert --volumes host                                                                             Path
        kompose.version: 1.21.0 (992df58d8)
      creationTimestamp: null
      labels:
        io.kompose.service: api
    spec:
      containers:
      - image: 127.0.0.1:5000/api:latest
        imagePullPolicy: "Never"
        name: api
        ports:
        - containerPort: 5001
        resources: {}
        volumeMounts:
        - mountPath: /api
          name: api-hostpath0
      restartPolicy: Always
      serviceAccountName: ""
      volumes:
      - hostPath:
          path: /root/api
        name: api-hostpath0
status: {}


apiVersion: v1
kind: Service
metadata:
  annotations:
    kompose.cmd: /snap/kompose/19/kompose-linux-amd64 convert --volumes hostPath
    kompose.version: 1.21.0 (992df58d8)
  creationTimestamp: null
  labels:
    io.kompose.service: api
  name: api
spec:
  ports:
  - name: "5001"
    port: 5001
    targetPort: 5001
  externalIPs:
    - 10.10.10.130

  selector:
    io.kompose.service: api
status:
  loadBalancer: {}
-- Batchen Regev
kubectl
kubernetes

1 Answer

8/23/2021

This is the service file, can you share the deployment or pod file that you have running? Somewhere it might have replicas count set to 3, you might need to change it to 1

-- Jay
Source: StackOverflow