How do you allow external services to hit a pod provisioned by the k8s jenkins plugin?

1/2/2019

What's the best way to allow ingress to a service running on a pod deployed by the Kubernetes Jenkins plugin?

I'm trying to write some integration tests. They require the system that I am testing to send a post to a URL. I am using the Kubernetes Plugin for Jenkins to provision the nodes where the tests will run.

During the tests, I would like to run a mock http server inside the pod , and have an external system hit this mock http server. I am using the declarative pipeline.

I tried just defining a service inside the Jenkinsfile like this :

pipeline {
  agent {
    kubernetes {
      label 'mypod'
      defaultContainer 'jnlp'
      yaml """
apiVersion: v1
kind: Pod
metadata:
  labels:
    some-label: some-label-value
spec:
  containers:
  - name: integration-test
    image: myimage:latest
    command:
    - cat
    tty: true

---

apiVersion: v1
kind: Service
metadata:
  name: webhooks-test
spec:
  selector:
    some-label: some-label-value
  ports:
  - protocol: TCP
    port: 3000
    targetPort: 9376
"""
    } 

This will deploy the pod, but won't define a service.

I haven't even tried defining an ingress rule.

It seems like defining a service in here isn't supported - after all , it's called a Pod Template! Is there another way to do this ? Perhaps the service and ingress rule should be applied manually, and the selector will only come into effect when the pod is deployed? I'm not sure how multiple pods will work then - ideally multiple tests should be able to be run at once. Thanks for any advice.

-- bortoelnino
jenkins
kubernetes

1 Answer

1/2/2019

I don't really understand why you want to create it this way but you could create the service before launching the tests as it will work for all pods started with that label

-- csanchez
Source: StackOverflow