Kubernetes - services without selector

kubernetes service selector
kubernetes headless service
kubernetes endpoints
kubernetes service external ip
kubernetes service load balancer
kubernetes service discovery
kubernetes access service from outside
kubernetes nodeport range

I'm struggling with Kubernetes' service without a selector. The cluster is installed on AWS with the kops. I have a deployment with 3 nginx pods exposing port 80:

apiVersion: apps/v1
kind: Deployment
metadata:
 name: ngix-dpl                 # Name of the deployment object
 labels:
   app: nginx                     
spec:
 replicas: 3                    # Number of instances in the deployment
 selector:                      # Selector identifies pods to be
     matchLabels:               #     part of the deployment 
        app: nginx              #     by matching of the label "app" 
 template:                      # Templates describes pods of the deployment
   metadata:
     labels:                    # Defines key-value map
       app: nginx               # Label to be recognized by other objects
   spec:                        #     as deployment or service
     containers:                # Lists all containers in the pod
     - name: nginx-pod          # container name
       image: nginx:1.17.4      # container docker image
       ports:
       - containerPort: 80      # port exposed by container

After creation of the deployment, I noted the IP addresses:

$ kubectl get pods -o wide | awk {'print $1" " $3" " $6'} | column -t
                                                                           NAME                       STATUS   IP
curl                       Running  100.96.6.40
ngix-dpl-7d6b8c8944-8zsgk  Running  100.96.8.53
ngix-dpl-7d6b8c8944-l4gwk  Running  100.96.6.43
ngix-dpl-7d6b8c8944-pffsg  Running  100.96.8.54

and created a service that should serve the IP addresses:

apiVersion: v1
kind: Service
metadata:
  name: dummy-svc
  labels:
    app: nginx
spec:
 ports:
    - protocol: TCP
      port: 80
      targetPort: 80
---
apiVersion: v1
kind: Endpoints
metadata:
  name: dummy-svc 
subsets: 
  - addresses:
    - ip: 100.96.8.53
    - ip: 100.96.6.43
    - ip: 100.96.8.54
    ports:
    - port: 80
      name: http

The service is successfully created:

$ kubectl get svc
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)   AGE
dummy-svc    ClusterIP   100.64.222.220   <none>        80/TCP    32m
kubernetes   ClusterIP   100.64.0.1       <none>        443/TCP   5d14h

Unfortunately, my attempt to connect to the nginx through the service from another pod of the same namespace fails:

$ curl 100.64.222.220
curl: (7) Failed to connect to 100.64.222.220 port 80: Connection refused

I can successfully connect to the nginx pods directly:

$ curl 100.96.8.53
<!DOCTYPE html>
<html>
<head>
....

I noticed that my service does not have any endpoints. But I'm not sure that the manual endpoints should be shown there:

$ kubectl get svc/dummy-svc -o yaml
apiVersion: v1
kind: Service
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |      
       {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"nginx"},"name":"dummy-svc","namespace":"default"},"spec":{"ports":[{"port":80,"protocol":"TCP","targetPort":80}]}}
  creationTimestamp: "2019-11-22T08:41:29Z"
  labels:
    app: nginx
  name: dummy-svc
  namespace: default
  resourceVersion: "4406151"
  selfLink: /api/v1/namespaces/default/services/dummy-svc
  uid: e0aa9d01-0d03-11ea-a19c-0a7942f17bf8
spec:
  clusterIP: 100.64.222.220
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  sessionAffinity: None
  type: ClusterIP
status:
  loadBalancer: {}

I understand that it is not a proper use case for services and using of a pod selector will bring it to work. But I want to understend why this configuration does not work. I don't know where to look for the solution. Any hint will be appreciated.

it works if you remove the "name" field from the endpoints configuration. it should look like this:

apiVersion: v1
kind: Endpoints
metadata:
  name: dummy-svc 
subsets: 
  - addresses:
    - ip: 172.17.0.4
    - ip: 172.17.0.5
    - ip: 172.17.0.6
    ports:
    - port: 80

Using a Service to Expose Your App, it works if you remove the "name" field from the endpoints configuration. it should look like this: apiVersion: v1 kind: Endpoints metadata: name:� Searching for Kubernetes Security? Check out Visymo. 1000+ Results From Across the Web. Start searching Kubernetes Security. All Web Results, One Search Engine.

correct the service definition as below

apiVersion: v1
kind: Service
metadata:
  name: dummy-svc
  labels:
    app: nginx
spec:
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
  selector:
   app: nginx

Kubernetes - services without selector, https://kubernetes.io/docs/user-guide/services/#services-without- port: 8080 targetPort: 8080 selector: service: alpha clusterIP: 10.3.250.250� Find Kubernetes security on search.sidewalk.com for Santa Clara. Results for Kubernetes security in Santa Clara

As @iliefa mentioned in his comment above, the below part of the definition is treated as labels in this type of cases.

ports:
    - port: 80
      name: http

In your scenario, we need to either remove 'name: http' as mentioned by @iliefa or we need to add 'name: http' under 'ports:' in the service definition as you can spot below.

apiVersion: v1
kind: Service
metadata:
  name: dummy-svc
  labels:
    app: nginx
spec:
 ports:
    - protocol: TCP
      port: 80
      targetPort: 80
      name: http

Service - Unofficial Kubernetes, When a service is defined without a selector, or with a selector that does not match any pods, then there will not be any endpoints created for that service. This is� Looking for kubernetes security? Search now! eTour.com is the newest place to search, delivering top results from across the web.

Services without selectors cannot forward to other services as , Services can be defined with or without a selector. Services support a variety of port definitions. Types of Kubernetes services. There are four� Find info on Trax.de. Here we have everything you need. What are kubernetes

Kubernetes Service, Service without Selector. apiVersion: v1 kind: Service metadata: name: Tutorial_point_service spec: ports: - port: 8080 targetPort: 31999. The above� Kubernetes - Service - A service can be defined as a logical set of pods. It can be defined as an abstraction on the top of the pod which provides a single IP address and DNS name by Home

Kubernetes Services: A Beginner's Guide – BMC Blogs, A Service enables network access to a set of Pods in Kubernetes. is made to the service, it selects all Pods in the cluster matching the service's selector, We could use a deployment without a service to keep a set of identical pods running � Services can be defined with or without a selector. Services support a variety of port definitions. Types of Kubernetes services. There are four types of Kubernetes services: ClusterIP. This default type exposes the service on a cluster-internal IP. You can reach the service only from within the cluster. NodePort.

Comments
  • yes but I don't understand how the meta-data is responsible for this?
  • it's not metadata. it works like a label. from kubernetes.io/docs/reference/generated/kubernetes-api/v1.15/… : name- The name of this port (corresponds to ServicePort.Name). Must be a DNS_LABEL. Optional only if one port is defined.
  • I know that the service with pod selector will work. I want to understand why my service with manual endpoints does not work.