0
votes

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
1
Edit the question to add output of kubectl get pods -n mynamespace --show-labelsArghya Sadhu
thanks @ArghyaSadhu already add the result of the commandPakorn K

1 Answers

1
votes

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