0

I create one pod with label:appenv and one service of type node port with a selector as appenv. But when I use kubectl get ep service-name it's showing "no endpoints"(means service is not connecting with that pod).
Here are my pod.yaml and service.yaml

pod.yaml

apiVersion: v1
kind: Pod
metadata:
  name: pod1
  labels:
    app: appenv
spec:
  containers:
  - name: app
    image: aathith/lbt:v1
    ports:
    - name: app-port
      containerPort: 8082
  restartPolicy: Never


service.yaml

apiVersion: v1
kind: Service
metadata:
  name: app
spec:
  selector:
    app: appenv
  type: NodePort
  ports:
  - name: http
    port: 8082
    targetPort: 8082
    nodePort: 30082
    protocol: TCP

output for kubectl get po --show-labels enter image description here

output for kubectl get svcenter image description here

output for kubectl get svc app

enter image description here

  1. Why am I not able to connect my pod to this service?
  2. How can I change the above files to connect with each other?
AATHITH RAJENDRAN
  • 4,689
  • 8
  • 34
  • 58

1 Answers1

2

Your pod is in "Completed" state - that is the problem. It is not in state "Running". Why? Because command in container was finished with 0 exit code. In normal situation container's running command should not exit unless it's a Job or Cronjob. You see what I mean?

Vasili Angapov
  • 8,061
  • 15
  • 31