Kubernetes sevice with CluserIp does not pass the request to some of it's Endpoints

2/21/2020

I'm new to Kubernetes. I have setup 3 node cluster with two workers according to here.
My configurations

kubectl version
Client Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.0", GitCommit:"641856db18352033a0d96dbc99153fa3b27298e5", GitTreeState:"clean", BuildDate:"2019-03-25T15:53:57Z", GoVersion:"go1.12.1", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.10", GitCommit:"575467a0eaf3ca1f20eb86215b3bde40a5ae617a", GitTreeState:"clean", BuildDate:"2019-12-11T12:32:32Z", GoVersion:"go1.12.12", Compiler:"gc", Platform:"linux/amd64"}
 kubeadm version
kubeadm version: &version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.0", GitCommit:"641856db18352033a0d96dbc99153fa3b27298e5", GitTreeState:"clean", BuildDate:"2019-03-25T15:51:21Z", GoVersion:"go1.12.1", Compiler:"gc", Platform:"linux/amd64"}

Deployed simple python service listen to 8000 port http and reply "Hello world"

my deployment config

apiVersion: apps/v1
kind: Deployment
metadata:
  name: frontend-app
  labels:
    app: frontend-app
spec:
  replicas: 2 
  selector:
    matchLabels:
      app: frontend-app
  template:
    metadata:
      labels:
        app: frontend-app
    spec:
      containers:
      - name: pyfrontend
        image: rushantha/pyfront:1.0 
        ports:
        - containerPort: 8000

Exposed this as a service kubectl expose deploy frontend-app --port 8000

I can see it deployed and running.

kubectl describe svc frontend-app
Name:              frontend-app
Namespace:         default
Labels:            app=frontend-app
Annotations:       <none>
Selector:          app=frontend-app
Type:              ClusterIP
IP:                10.96.113.192
Port:              <unset>  8000/TCP
TargetPort:        8000/TCP
Endpoints:         172.16.1.10:8000,172.16.2.9:8000
Session Affinity:  None
Events:            <none>

when I log in to each service machine and do curl pods respond ie. curl 172.16.1.10:8000 or curl 172.16.2.9:8000

However when I try to access the pods via the ClusterIp only one pod always responds. So curl sometimes hangs, most probably the other pod does not respond. I confirmed when I tail the access logs for both pods. One pod never received any requests.

curl 10.96.113.192:8000/ ---> Hangs sometimes.

Any ideas how to troubleshoot this and fix ?

-- Sajith Silva
http
kubernetes

1 Answer

2/24/2020

After comparing the tutorial document and the outputs configuration I discovered that the --pod-network-cidr declared in the document is different from the OP endpoints which solved the problem.

The network in the flannel configuration should match the pod network CIDR otherwise pods won`t be able to communicate with each other.

Some additional information that are worth checking:

  1. Under the CIDR Notation section there is a good explanation how this system works.

  2. I find this document about networking in kuberenetes very helpful.

-- acid_fuji
Source: StackOverflow