Service does not work after deleting one pod in a deployment

7/17/2020

I apply a deployment of 2 some http pods, and a service for it, and it works fine. I can curl the serviceip or servicename. The service did round robin well.
But after I delete one pod, k8s create a new one to replace it. When I curl the service, the new pod doesn't return, only the other old one is OK.
The question is why k8s not update new pod to the service so I can curl the serviceip or servicename as before?

Deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mvn-dp
spec:
  selector:
    matchLabels:
      run: mvn-demo
  replicas: 2
  template:
    metadata:
      labels:
        run: mvn-demo
    spec:
      containers:
      - name: mvndemo
        image: 192.168.0.193:59999/mvndemo
        ports:
        - containerPort: 8080

Service:
apiVersion: v1
kind: Service
metadata:
  name: mvn-svc
  labels:
    run: mvn-demo
spec:
  ports:
  - port: 8080
    protocol: TCP
  #type: NodePort
  selector:
    run: mvn-demo

kdes svc mvn-svc

Name:              mvn-svc
Namespace:         default
Labels:            run=mvn-demo
Annotations:       Selector:  run=mvn-demo
Type:              ClusterIP
IP:                10.97.21.218
Port:              <unset>  8080/TCP
TargetPort:        8080/TCP
Endpoints:         100.101.153.220:8080,100.79.233.220:8080
Session Affinity:  None
Events:            <none>

kpod

NAME                                READY   STATUS    RESTARTS   AGE   IP                NODE      NOMINATED NODE   READINESS GATES
mvn-dp-8f59c694f-2mwq8              1/1     Running   0          81m   100.79.233.220    worker2   <none>           <none>
mvn-dp-8f59c694f-xmt6m              1/1     Running   0          87m   100.101.153.220   worker3   <none>           <none>

[root@master1 k8s-yaml]# curl http://10.97.21.218:8080
Hello Docker World, from: mvn-dp-8f59c694f-xmt6m
[root@master1 k8s-yaml]# curl http://10.97.21.218:8080
**curl: (7) Failed connect to 10.97.21.218:8080; 连接超时(connetion timeout)**

As u can see the age of mvn-dp-8f59c694f-2mwq8 is newer than the other one, because I deleted one pod and k8s replace it with this new one.

-- james h
kubernetes

1 Answer

7/17/2020

Set a label to your deployment metadata

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mvn-dp
  labels:
    run: mvn-demo

it will work

-- Sergio Tanaka
Source: StackOverflow