Kubernetes: Can not telnet to ClusterIP Service inside my Cluster

8/26/2017

I want to deploy Jenkins on a local Kubernetes cluster (no cloud). I will create 2 services above Jenkins. One service of type NodePort for port 8080 (be mapped on random port and I can access it outside the cluster. I can also access it inside the cluster by using ClusterIP:8080). All fine.

My second service is so my Jenkins slaves can connect. I choose for a ClusterIP (default) as type of my service:

I read about the 3 types of services:

  • clusterIP:

Exposes the service on a cluster-internal IP. Choosing this value makes the service only reachable from within the cluster.

  • NodePort: is not necessary for 50000 to expose outside cluster
  • Loadbalancer: I'm not working in the cloud

Here is my .yml to create the services:

  kind: Service
  apiVersion: v1
  metadata:
    name: jenkins-ui
    namespace: ci
  spec:
    type: NodePort
    selector:
      app: master
    ports:
      - protocol: TCP
        port: 8080
        targetPort: 8080
        name: master
---
  kind: Service
  apiVersion: v1
  metadata:
    name: jenkins-discovery
    namespace: ci
  spec:
    #type: ClusterIP
    selector:
      app: jenkins
    ports:
      - protocol: TCP
        port: 50000
        targetPort: 50000
        name: slaves

The problem is that my slaves can not connect to port 50000. I tried to telnet the ClusterIP:port of the service jenkins-discovery and I got a connection refused. I can telnet to ClusterIP:port of the jenkins-ui service. What am I doing wrong or is there a part I don't understand?

-- lvthillo
jenkins
kubernetes

1 Answer

8/27/2017

It's solved. The mistake was the selector which is a part which wasn't that clear for me. I was using different nodeselectors what seemed to cause this issue. This worked:

 kind: Service
  apiVersion: v1
  metadata:
    name: jenkins-ui
    namespace: ci
  spec:
    type: NodePort
    selector:
      app: master
    ports:
      - protocol: TCP
        port: 8080
        targetPort: 8080
        name: master
---
  kind: Service
  apiVersion: v1
  metadata:
    name: jenkins-discovery
    namespace: ci
  spec:
    #type: ClusterIP
    selector:
      app: master
    ports:
      - protocol: TCP
        port: 50000
        targetPort: 50000
        name: slaves
-- lvthillo
Source: StackOverflow