"kubernetes" service in minikube

3/7/2020

I have accidentally deleted all the services in my minikube setup, including "kubernetes" service in the default namespace.

But within a few seconds, I noticed the "kubernetes" service created again, automatically. If I understand corrected, the replica in deployment takes care of only pods, right? I am wondering how this "kubernetes" service created automatically and what is the use of this service after all.

$ kubectl get svc -owide
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE   SELECTOR
kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   13m   <none>

$ kubectl delete svc kubernetes                              
service "kubernetes" deleted

$ kubectl get svc -owide
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE   SELECTOR
kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   3s    <none>

Is there a way we can implement the same functionality for our own service?

E.g. whenever it gets deleted, it should be recreated automatically.

-- smc
kubernetes
kubernetes-service
minikube

1 Answer

3/7/2020

Kuberneetes API server will recreate it. You can check below line in the logs of Kubernetes API Server right after you delete the service.

Resetting endpoints for master service "kubernetes" to

This service is used when you want to interact with Kubernetes API Server from pods using a service account.

Check the source code.

-- Arghya Sadhu
Source: StackOverflow