Exposing the same service with same URL but two different ports with traefik?

10/13/2017

recently I am trying to set up CI/CD flow with Kubernetes v1.7.3 and jenkins v2.73.2 on AWS in China (GFW blocking dockerhub).

Right now I can expose services with traefik but it seems I cannot expose the same service with the same URL with two different ports.

Ideally I would want expose http://jenkins.mydomain.com as jenkins-ui on port 80, as well as the jenkin-slave (jenkins-discovery) on port 50000. For example, I'd want this to work:

apiVersion: extensions/v1beta1 kind: Ingress metadata: name: jenkins namespace: default spec: rules: - host: jenkins.mydomain.com http: paths: - path: / backend: serviceName: jenkins-svc servicePort: 80 - host: jenkins.mydomain.com http: paths: - path: / backend: serviceName: jenkins-svc servicePort: 50000 and my jenkins-svc is defined as

apiVersion: v1 kind: Service metadata: name: jenkins-svc labels: run: jenkins spec: selector: run: jenkins ports: - port: 80 targetPort: 8080 name: http - port: 50000 targetPort: 50000 name: slave

In reality the latter rule overwrites the former rule.

Furthermore, There are two plugins I have tried: kubernetes-cloud and kubernetes. With the former option I cannot configure jenkins-tunnel URL, so the slave fails to connect with the master; with the latter option I cannot pull from a private docker registry such as AWS ECR (no place to provice credential), therefore not able to create the slave (imagePullError).

Lastly, really I am just trying to get jenkins to work (create slaves with my custom image, build with slaves and delete slaves after jobs' finished ), any other solution is welcomed.

-- Benson Zhang
amazon-web-services
jenkins
kubernetes
traefik

1 Answer

10/13/2017

If you want your jenkins to be reachable from outside of your cluster then you need to change your ingress configuration.

Default type of ingress type is ClusterIP

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

You want it type to be NodePort

Exposes the service on each Node’s IP at a static port (the NodePort). A ClusterIP service, to which the NodePort service will route, is automatically created. You’ll be able to contact the NodePort service, from outside the cluster, by requesting :

So your service should look like:

apiVersion: v1 kind: Service metadata: name: jenkins-svc labels: run: jenkins spec: selector: run: jenkins type: NodePort ports: - port: 80 targetPort: 8080 name: http - port: 50000 targetPort: 50000 name: slave

-- 3h4x
Source: StackOverflow