1
votes

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?

1
Assuming you've got the DNS add-on enabled, what does, from within the cluster, curl jenkins-discovery.default.svc.cluster.local give you?Michael Hausenblas
i know you said "no cloud", but maybe you would figure out what is going wrong by trying github.com/GoogleCloudPlatform/…? or this non-cloud walk-through: blog.kublr.com/…burnettk
Can you check kubectl get ep jenkins-ui -n ci ? Could it be a problem with your selector or a maybe a readinessProbe you have on the Jenkins master?Janos Lenart
@JanosLenart the output of your command is: jenkins-ui 10.42.120.179:8080 1d. For discovery it has Endpoints <none> where jenkins-UI has serviceIP:Portlvthillo
@MichaelHausenblas I'm pretty new to this. I don't know if it's enabled. The curl does not work inside my cluster. I can curl kubernetes.default.svc.lvthillo

1 Answers

0
votes

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