Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the purpose of the default kubernetes service?

Tags:

kubernetes

When you run: kubectl get svc -n default, you will have a kubernetes service with Type as ClusterIP already there.

What is the purpose of this service? Any references appreciated.

I'm running in Minikube

xyz:Kubernetes _$ kubectl describe svc/kubernetes
Name:              kubernetes
Namespace:         default
Labels:            component=apiserver
               provider=kubernetes
Annotations:       <none>
Selector:          <none>
Type:              ClusterIP
IP:                10.0.0.1
Port:              https  443/TCP
TargetPort:        8443/TCP
Endpoints:         10.0.2.15:8443
Session Affinity:  ClientIP
Events:            <none>

xyz:Kubernetes _$ kubectl cluster-info
Kubernetes master is running at https://192.168.99.100:8443
like image 200
Fei Avatar asked Nov 28 '17 02:11

Fei


People also ask

What is the use of default Kubernetes service?

What is the Kubernetes ClusterIP service? ClusterIP is the default type of service, which is used to expose a service on an IP address internal to the cluster.

What is default service account in Kubernetes?

Every Kubernetes installation has a service account called default that is associated with every running pod. Similarly, to enable pods to make calls to the internal API Server endpoint, there is a ClusterIP service called Kubernetes. This combination makes it possible for internal processes to call the API endpoint.

What are the default pods in Kubernetes?

By default, Pods run on nodes in the default node pool for the cluster. You can configure the node pool a Pod selects explicitly or implicitly: You can explicitly force a Pod to deploy to a specific node pool by setting a nodeSelector in the Pod manifest. This forces a Pod to run only on Nodes in that node pool.

What is the use of service named with Kubernetes in default namespace?

AFAIK the kubernetes service in the default namespace is a service which forwards requests to the Kubernetes master ( Typically kubernetes API server). Lets checkout the output of kubectl describe svc kubernetes and look at the the Endpoint IP.


2 Answers

AFAIK the kubernetes service in the default namespace is a service which forwards requests to the Kubernetes master ( Typically kubernetes API server).

So all the requests to the kubernetes.default service from the cluster will be routed to the configured Endpoint IP. In this scenario its the kubernetes master IP

For example

Lets checkout the output of kubectl describe svc kubernetes and look at the the Endpoint IP.

enter image description here

Now lets check our cluster info

kubectl cluster-info

enter image description here

Please note that the kubernetes master is running at the same IP as the Endpoints IP of kubernetes.default service.

Hope it helps.

like image 95
Karthik Venkateswaran Avatar answered Sep 30 '22 17:09

Karthik Venkateswaran


It is so that every Pod within your cluster can make API requests of the Kubernetes master without having to hard-code the API URL therein. Your ~/.kube/config may very well have the "external" address of your Kubernetes master, but it makes very little sense for API traffic to leave the cluster and then re-enter the cluster for a Pod that could be co-located on the same Node. Pods are able to use the Service Account credentials injected by kubernetes, unless that Service Account feature is disabled per-Pod.

Your application is free to make use of that functionality, too, if it wishes -- for example -- to discover any annotations on its Pod, or how many other replicas there are in its Deployment, and so forth.

I guess the tl;dr is that for 90% of the Pods it doesn't matter, and for the remaining 10% it is super convenient.

like image 44
mdaniel Avatar answered Sep 30 '22 15:09

mdaniel