i'm getting:0/3 nodes are available: 3 node(s) didn't have free ports for the requested pod ports.
while trying to run multiple jenkins slaves on the same k8s node.
each pod exposes a the same ports, this making it impossible to run 2 same pods on the same node.
i have a service with a load balancer - but its not doing the trick.
is there a possibility to create a service that will generate random ports for each pod created?
Thanks!!!
edit: this is the service configured:
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": "jnlp",
"namespace": "default",
"selfLink": "/api/v1/namespaces/default/services/jnlp",
"uid": "345230eb-5078-11e9-959a-1690183aeeb4",
"resourceVersion": "90390",
"creationTimestamp": "2019-03-27T10:08:01Z",
"annotations": {.....}
},
"spec": {
"ports": [
{
"name": "ssh",
"protocol": "TCP",
"port": 22,
"targetPort": 22,
"nodePort": 32417
}
],
"selector": {
"app": "jnlp"
},
"clusterIP": "....",
"type": "LoadBalancer",
"sessionAffinity": "None",
"externalTrafficPolicy": "Cluster"
},
"status": {
"loadBalancer": {
"ingress": [
{
"ip": "......"
}
]
}
}
}
jenkins config:
podTemplate(label: slave,
containers: [
containerTemplate(name: 'mongodb',
image: mongo_image,
ttyEnabled: true,
ports: [portMapping(name: 'mongo', containerPort: 27017, hostPort: 27017)],
),
containerTemplate(name: 'elasticsearch',
image: elastic_image,
ttyEnabled: true,
ports: [portMapping(name: 'elastic', containerPort: 9200, hostPort: 9200)],
),
containerTemplate(name: 'jnlp',
image: "******:${CONTAINER_TAG}",
command: 'jenkins-slave',
alwaysPullImage: true,
privileged: true,
label: 'jnlp',
envVars: [
envVar(key: 'HOME', value: "${JENKINS_HOME}"),
])
],
imagePullSecrets: ['*******'],
podRetention: always()
)
You cannot have multiple pods use the same nodePort
since this is a port on the actual machine that you will be binding to your pod. Since you are using a loadbalancer I don't see why you would need to use nodePorts. If you don't absolutely need to use nodePorts, simply remove it from your service.