1

I have a deployment that consists on one Job that contains two containers. Due to distribution and economical reasons, I want these two containers to be deployed independently. However, they are still interconnected. This means there should be network communication between both of them.

As far as I know, you can not create a Service over a Job. You need it to be at least a simple Pod. However, this adds another element and modifies the equation: I want to split the Job into two Jobs, not into one Job, one Pod and one Service.

So, with this as context, is there a way to connect to Jobs directly without creating a service? They both are going to be on the same cluster, using the same internal DNS, in different machines.

Basically, something like, from Job1, connect to job1.job1namespace:8080.

1

You might be able (assuming you're running at least Kubernetes 1.20) to leverage a beta feature for the Pod spec that allows a Pod FQDN to be set in DNS.

I am uncertain if this extends to Job resources in the minimum version (v1.20), but because it is part of the Pod specification, I would assume so between Jobs. In this example, assuming setHostnameAsFQDN: true is set for that definition, a FQDN like busybox-1.default-subdomain.my-namespace.svc.cluster-domain.example (for a name metadata field called busybox for that spec) would be valid, and should be accessible from a different Job.

I was able to test that Job resources would accept setHostnameAsFQDN in the definition, and it seemed to without issue:

apiVersion: batch/v1
kind: Job
metadata:
  name: pi
spec:
  template:
    spec:
      containers:
      - name: pi
        image: perl
        command: ["perl",  "-Mbignum=bpi", "-wle", "print bpi(2000)"]
      restartPolicy: Never
      setHostnameAsFQDN: true
  backoffLimit: 4

on Kubernetes v1.21.1.

1
  • Very good answer. However, we are using Kubernetes 1.19 right now. I'll try to find if it is possible to update to 1.20 at least, because 1.21 is still not available at AWS EKS. – msolefonte Jun 3 at 8:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.