<p>I have two jobs that will run only once. One is called <code>Master</code> and one is called <code>Slave</code>. As the name implies a Master pod needs some info from the slave then queries some API online.
A simple scheme on how the communicate can be done like this:</p>

<pre><code>Slave --- port 6666 ---&gt; Master ---- port 8888 ---&gt; internet:www.example.com
</code></pre>

<p>To achieve this I created 5 yaml file:</p>

<ol>
<li>A job-master.yaml for creating a Master pod:</li>
</ol>

<pre><code>apiVersion: batch/v1
kind: Job
metadata:
  name: master-job
  labels:
    app: master-job
    role: master-job
spec:
  template:
    metadata:
      name: master
    spec:
      containers:
      - name: master
        image: registry.gitlab.com/example
        command: ["python", "run.py", "-wait"]
        ports:
        - containerPort: 6666

      imagePullSecrets:
      - name: regcred
      restartPolicy: Never

</code></pre>

<ol>
<li>A service (ClusterIP) that allows the Slave to send info to the Master node on port 6666:</li>
</ol>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: master-service
  labels:
    app: master-job
    role: master-job
spec:
  selector:
    app: master-job
    role: master-job
  ports:
    - protocol: TCP
      port: 6666
      targetPort: 6666
</code></pre>

<ol start="2">
<li>A service(NodePort) that will allow the master to fetch info online:</li>
</ol>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: master-np-service
spec:
  type: NodePort
  selector:
    app: master-job
  ports:
    - protocol: TCP
      port: 8888
      targetPort: 8888
      nodePort: 31000
</code></pre>

<ol start="3">
<li>A job for the Slave pod:</li>
</ol>

<pre><code>apiVersion: batch/v1
kind: Job
metadata:
  name: slave-job
  labels:
    app: slave-job
spec:
  template:
    metadata:
      name: slave
    spec:
      containers:
      - name: slave
        image: registry.gitlab.com/example2
        ports:
        - containerPort: 6666
        #command: ["python", "run.py", "master-service.default.svc.cluster.local"]
        #command: ["python", "run.py", "10.106.146.155"]
        command: ["python", "run.py", "master-service"]
      imagePullSecrets:
      - name: regcred
      restartPolicy: Never
</code></pre>

<ol start="5">
<li>And a service (ClusterIP) that allows the Slave pod to send the info to the Master pod:</li>
</ol>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: slave-service
spec:
  selector:
    app: slave-job
  ports:
    - protocol: TCP
      port: 6666
      targetPort: 6666
</code></pre>

<p>But no matter what I do (as it can be seen in the job_slave.yaml file in the commented lines) they cannot communicate with each other except when I put the IP of the Master node in the command section of the Slave. Also the Master node cannot communicate with the outside world (even though I created a <code>configMap</code> with <code>upstreamNameservers: | ["8.8.8.8"]</code>
Everything is running in a minikube environment.
But I cannot pinpoint what my problem is. Any help is appreciated. </p>

Andi Domi
<p>Your Job spec has two parts: a description of the Job itself, and a description of the Pods it creates.  (Using a Job here is a little odd and I'd probably pick a Deployment instead, but the same applies here.)  Where the Service object has a <code>selector:</code> that matches the <code>labels:</code> of the Pods.</p>

<p>In the YAML files you show the Jobs have correct labels but the generated Pods don't.  You need to add (potentially duplicate) labels to the pod spec part:</p>

<pre><code>apiVersion: batch/v1
kind: Job
metadata:
  name: master-job
  labels: {...}
spec:
  template:
    metadata:
      # name: will get ignored here
      labels:
        app: master-job
        role: master-job
</code></pre>

<p>You should be able to verify with <code>kubectl describe service master-service</code>.  At the end of its output will be a line that says <code>Endpoints:</code>.  If the Service selector and the Pod labels don't match this will say <code>&lt;none&gt;</code>; if they do match you will see the Pod IP addresses.</p>

<p>(You don't need a <code>NodePort</code> service unless you need to <em>accept</em> requests from outside the cluster; it could be the same as the service you use to accept requests from within the cluster.  You don't need to include objects' types in their names.  Nothing you've shown has any obvious relevance to communication out of the cluster.)</p>
