Pakorn K
Pakorn K

Reputation: 121

Kubernetes apply service but endpoints is none

When I tried to apply a service to pod, endpoint is always none. Could someone know any root cause? I also check if selector match to what is defined in the deployment.yaml. Belows are the deployment, service file that I used. I also attached the service describe.

deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: gethnode
  namespace: mynamespace
  labels:
    app: gethnode
    env: dev1
spec:
  replicas: 1
  selector:
    matchLabels:
      app: gethnode
      env: dev1
  template:
    metadata:
      labels:
        app: gethnode
        env: dev1
    spec:
      containers:
      - name: gethnode
        image: myserver.th/bc/gethnode:1.1
        ports:
        - containerPort: 8550
        env:
        - name: TZ
          value: Asis/Bangkok
        tty: true
        stdin: true
        resources:
          limits:
            cpu: 500m
            memory: 512Mi
          requests:
            cpu: 500m
            memory: 512Mi
      imagePullSecrets:
      - name: regcred-harbor

service.yaml

apiVersion: v1
kind: Service
metadata:
  name: gethnode
  namespace: mynamespace
  labels:
    app: gethnode
    env: dev1
spec:
  type: ClusterIP
  ports:
  - name: tcp
    port: 8550
    targetPort: 8550
    protocol: TCP
  selector:
    app: gethnode
    env: dev1    

kubectl describe svc

Name:              gethnode
Namespace:         mynamespace
Labels:            app=gethnode
                   env=dev1
Annotations:       kubectl.kubernetes.io/last-applied-configuration:
                     {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"gethnode","env":"dev1"},"name":"gethnode","namespace":"c...
Selector:          app=gethnode,env=dev1
Type:              ClusterIP
IP:                192.97.37.19
Port:              tcp  8550/TCP
TargetPort:        8550/TCP
Endpoints:         <none>
Session Affinity:  None
Events:            <none>

kubectl get pods -n mynamespace --show-labels

NAME                              READY   STATUS             RESTARTS   AGE    LABELS
console-bctest-6bff897bf4-xmch8   1/1     Running            0          6d3h   app=bctest,env=dev1,pod-template-hash=6bff897bf4
console-dev1-595c47c678-s5mzz     1/1     Running            0          20d    app=console,env=dev1,pod-template-hash=595c47c678
gethnode-7f9b7bbd77-pcbfc         1/1     Running            0          3s     app=gethnode,env=dev1,pod-template-hash=7f9b7bbd77
gotty-dev1-59dcb68f45-4mwds       0/2     ImagePullBackOff   0          20d    app=gotty,env=dev1,pod-template-hash=59dcb68f45

kubectl get svc gethnode -n mynamespace -o wide

NAME       TYPE        CLUSTER-IP        EXTERNAL-IP   PORT(S)    AGE   SELECTOR
gethnode   ClusterIP   192.107.220.229   <none>        8550/TCP   64m   app=gethnode,env=dev1

Upvotes: 3

Views: 5807

Answers (2)

Cesar Celis
Cesar Celis

Reputation: 306

I had same issue, and what I did was to delete the Deployment, Secrets associated, Service, and Ingress to start fresh. Then make sure that my Deployment is consistent with my service in the naming, specifically talking about app.kubernetes.io/name as I used to have just name in my deployment and app.kubernetes.io/name in my service causing this discrepancy. In any case, now I got endpoints populated:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: webhook
  namespace: apps
  labels:
    app.kubernetes.io/name: webhook
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: webhook
  template:
    metadata:
      labels:
        app.kubernetes.io/name: webhook
    spec:
      containers:
      - name: webhook
        image: registry.min.dev/minio/webhook:latest
        ports:
        - name: http
          containerPort: 23411
        env:
        - name: GH_TOKEN
          valueFrom:
            secretKeyRef:
              name: webhooksecret
              key: GH_TOKEN
      imagePullSecrets:
        - name: registry-creds
apiVersion: v1
kind: Service
metadata:
  name: webhook
  namespace: apps
  labels:
    app.kubernetes.io/name: webhook
spec:
  ports:
    - name: http
      port: 23411
  selector:
    app.kubernetes.io/name: webhook

And as a result:

$ k get ep webhook -n apps
NAME      ENDPOINTS              AGE
webhook   192.168.177.67:23411   4m15s
                 |
                 |___ Got populated!

Upvotes: 1

Arghya Sadhu
Arghya Sadhu

Reputation: 44687

Remove env: dev1 from the selector of the service

apiVersion: v1
kind: Service
metadata:
  name: gethnode
  namespace: mynamespace
  labels:
    app: gethnode
    env: dev1
spec:
  type: ClusterIP
  ports:
  - name: tcp
    port: 8550
    targetPort: 8550
    protocol: TCP
  selector:
    app: gethnode

Upvotes: 2

Related Questions