Kubernetes Cronjob with Service

7/4/2018

Im running a Kubernetes Cluster on my mashines with the version: v1.10.3

So I start cronjob with the sakuli framework to check my own websites. When anything fails it sends to icinga, but I can't look into it. Normally the sakuli frameworks has an open port (6901) where you can connect. This works, if I build it with a cron job in a container. But how can I expose a port on a public adress (I mean the NodePort option in kubernete) with a cronjon who runs only every 5 minutes and not the complete time?

-- Theroth
kubectl
kubernetes

2 Answers

7/4/2018

You can expose it with a regular service object. CronJob results in Pod creation. Service matches labels on Pods. As long as labels match it will become an endpoint for that service. With a CronJob based pods you will just end up in a situation where when there is no pod active, your service has no endpoints, when it's there, it'll be possible to use it normally.

-- Radek 'Goblin' Pieczonka
Source: StackOverflow

7/4/2018

You can find the examples of usage in kubernetes folder in the official repo on Github.

In this example, you can find kind: Service, this is what you need as an example of how to expose your jobs.

As described in this example, for exposing your pod service it is enough, but it will be available only when pod with a job will exist.

-- Nick Rak
Source: StackOverflow