Here is a Kubernetes yaml file:
apiVersion: apps/v1
kind: Deployment
metadata:
name: opp-deployment
spec:
replicas: 2
selector:
matchLabels:
app: opp
template:
metadata:
labels:
app: opp
spec:
containers:
- name: opp-container
image: opp_svc:1.0.2
ports:
- containerPort: 51061
---
apiVersion: v1
kind: Service
metadata:
name: opp-service
spec:
selector:
app: opp
ports:
- protocol: TCP
port: 8080
targetPort: 51061
type: LoadBalancer
So, “kubectl apply -f ./kube-start-opp-svc.yaml” run succesfully and able to see 2 pods running.
Now, to be able to make a http call to the “opp-service”, run in dedicated terminal this command:
kubectl port-forward service/opp-service 8080:8080
to forward request from my local machine to the service and I am expecting the service to use “round-robin” algorithm to send request to different pods.
So, I have 2 pods:
opp-deployment-85dc5b8496-b7qnn and opp-deployment-85dc5b8496-xsnvd
For some reason all request are going only to the pod: opp-deployment-85dc5b8496-xsnvd
I’ve used “curl http://localhost:8080/health” command to run serveral times from one terminal, from another terminal and the I coded a go program that makes 10 parallel request every 1 seconds.
All calls goes to the same pod. Why?