Endpoint is not Created for Service in Kubernetes

The Problem

Endpoints shows ‘none’:

$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.yy.0.1 <none> 443/TCP 9d
test ClusterIP 10.xx.97.97 <none> 6379/TCP 21s
$ kubectl describe svc test
Name: test
Namespace: default
Labels: <none>
Annotations: kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"test","namespace":"default"},"spec":{"clusterIP":"10.xx.97.97","...
Selector: app=test
Type: ClusterIP
IP: 10.xx.97.97
Port: <unset> 6379/TCP
TargetPort: 6379/TCP
Endpoints: <none>
Session Affinity: None
Events: <none>

The Solution

The service selector doesn’t match any Pod’s labels.

$ kubectl get pods --show-labels |egrep 'app=test'
$

1. Edit the yaml file and correct the selector to match the Pod’s label.

$ kubectl get pods --show-labels |egrep 'app=filebeat'
myapp-ds-c2fwm 1/1 Running 0 21h app=filebeat,controller-revision-hash=54ccfc87bd,pod-template-generation=1,release=stable
myapp-ds-rbn4z 1/1 Running 0 21h app=filebeat,controller-revision-hash=54ccfc87bd,pod-template-generation=1,release=stable
$ vi test-svc.yaml
apiVersion: v1
apiVersion: v1
kind: Service
metadata:
name: test
namespace: default
spec:
selector:
app: filebeat
clusterIP: 10.xx.97.97
type: ClusterIP
ports:
- port: 6379
targetPort: 6379

2. Apply the configuration:

$ kubectl apply -f test-svc.yaml
service/test created
$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.yy.0.1  443/TCP 9d
test ClusterIP 10.xx.97.97  6379/TCP 29m

3. Show the details of the service:

$ kubectl describe svc test
Name: test
Namespace: default
Labels: [none]
Annotations: kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"test","namespace":"default"},"spec":{"clusterIP":"10.xx.97.97","...
Selector: app=filebeat
Type: ClusterIP
IP: 10.xx.97.97
Port: [unset] 6379/TCP
TargetPort: 6379/TCP
Endpoints: 10.zzz.1.38:6379,10.zzz.2.36:6379
Session Affinity: None
Events: [none]
$ kubectl get endpoints test
NAME ENDPOINTS AGE
test 10.zzz.1.38:6379,10.zzz.2.36:6379 39m
Related Post