why was k8s service deleted but the cluster IP works still

5/28/2020

I can easily reporduce this and could not find an answer for this issue either in k8s doc or the community.

Simple reproduce steps:

  1. create service and endpoint with below config
---
kind: Service
apiVersion: v1
metadata:
  name: hostname
spec:
  type: ClusterIP
  ports:
  - port: 80
    targetPort: 9376

---
kind: Endpoints
apiVersion: v1
metadata:
  name: hostname
subsets:
  - addresses:
      - ip: 10.244.44.250
      - ip: 10.244.154.235
    ports:
      - port: 9376
  1. kubectl apply -f <filename> to apply the config
  2. test the service and it works perfect. Assume the cluster IP is A
  3. kubectl delete -f <filename> to delete the service and endpoint and kubectl apply -f <filename> again
  4. we got another cluser IP B, which works perfect also
  5. however, cluser IP A was not removed as expected. I can use A to access the service still.
  6. Update the endpoint definition (add new endpoint IP or remove one) and apply, B sees the change while A uses old config still.

Is there someone can explain what happens there?

My k8s version is:

Server Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.1", GitCommit:"4485c6f18cee9a5d3c3b4e523bd27972b1b53892", GitTreeState:"clean", BuildDate:"2019-07-18T09:09:21Z", GoVersion:"go1.12.5", Compiler:"gc", Platform:"linux/amd64"}
-- Bingfeng
kubernetes
service

0 Answers