Hi guys, Are endpoints same as services? I mean whenever we expose any resource . . .

R S:
Hi guys, Are endpoints same as services? I mean whenever we expose any resource using kubectl expose it create a service which can be seen using kubectl get ep so how are the services different from endpoints :confused:

Gautam Venkataramanan:
endpoints are the backend pods of a service. clients usually know only the services (not the endpoints). When clients send a request to service, the service will load balance traffic to one of the endpoint pods. hope this helps.

Craig Shea:
Also, if you create a service with no pod selector, then no endpoints are created. In this case, you’d have to manually create endpoints for the service. Why would you do this? I don’t remember–only that I read about it recently and that it sometimes comes in handy.

maheshwar reddy:
For statefulsets service with out selector we use

runlevl4:
If you don’t want/need load balancing, you can also create a headless service. You get the same endpoints but without the load balancing aspect.

R S:
@Gautam Venkataramanan I am still not clear. So, if there are 100 pods, then the kubectl get ep shall list these 100s IPs in the endpoint column?

runlevl4:
Yes. Try the command. Here is a service with three pods.
nginx-svc 10.244.0.17:80,10.244.0.18:80,10.244.0.19:80

Gautam Venkataramanan:
@R S, correct. But if you just create pods and dont tie it to any service, then those wont be listed under endpoints.

R S:
Ok, after messing up some time with multi-container pods and services with multiple ports. I realised that and endpoint will be created by service for each ports mentioned or supplied to service.

R S:
## Pod 3
apiVersion: “v1”
kind: Pod
metadata:
name: pod3
labels:
app: endpoint-demo
spec:
containers:
- name: httpd
image: httpd
ports:
- containerPort: 8086
name: httpd-port
- name: redis
image: redis
ports:
- containerPort: 8087
name: redis-port


SVC

apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
app: endpoint-demo
name: demo-svc
spec:
ports:

  • name: svc-port1
    port: 8086
  • name: svc-port2
    port: 8087
    selector:
    app: endpoint-demo
    type: ClusterIP

R S:
https://stackoverflow.com/questions/52857825/what-is-an-endpoint-in-kubernetes#:~:text=An%20endpoint%20is%20an%20object,individual%20pods%20assigned%20to%20it.&text=We%20need%20endpoints%20as%20an,sending%20traffic%20to%20healthy%20pods).