title: Access kubernetes job pods using hostname
body: <p>I am trying to run a k8s job with 2 pods in which one pod will try to connect to other pod.</p>
  <p>I cannot connect to other pod using hostname of the pod as suggested in the doc - <a href="https://kubernetes.io/docs/concepts/workloads/controllers/job/#completion-mode" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/workloads/controllers/job/#completion-mode</a>.</p>
  <p>I have created a service and trying to access the pod as <code>k8s-train-0.default.svc.cluster.local</code> as mentioned in the document.</p>
  <pre><code>apiVersion: batch/v1
  kind: Job
  metadata:
    name: k8s-train
  spec:
    parallelism: 2
    completions: 2
    completionMode: Indexed
    manualSelector: true
    selector:
      matchLabels:
        app.kubernetes.io/name: proxy
    template:
      metadata:
        labels:
          app.kubernetes.io/name: proxy
      spec:
        containers:
        - name: k8s-train
          image: pytorch/pytorch:1.11.0-cuda11.3-cudnn8-runtime
          command: [&quot;/bin/sh&quot;,&quot;-c&quot;]
          args:
            - echo starting;
              export MASTER_PORT=54321;
              export MASTER_ADDR=k8s-train-0.trainsvc.default.svc.cluster.local;
              export WORLD_SIZE=8;
              pip install -r /data/requirements.txt;
              export NCCL_DEBUG=INFO;
              python /data/bert.py --strategy=ddp --num_nodes=2 --gpus=4 --max_epochs=3;
              echo done;
          env:
            - name: MY_POD_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
          ports:
            - containerPort: 54321
              name: master-port
          resources:
            requests:
              nvidia.com/gpu: 4
            limits:
              nvidia.com/gpu: 4
          volumeMounts:
            - mountPath: /data
              name: data
        volumes:
          - name: data
            persistentVolumeClaim:
              claimName: efs-claim
        restartPolicy: Never
    backoffLimit: 0
  ---
  apiVersion: v1
  kind: Service
  metadata:
    name: trainsvc
  spec:
    selector:
      app.kubernetes.io/name: proxy
    ports:
    - name: master-svc-port
      protocol: TCP
      port: 54321
      targetPort: master-port
    clusterIP: None
  </code></pre>
  <p><a href="https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/</a></p>
  <p>I am looking to establish communication between pod either using the hostname or to assign svc only to one pod slected with job-index.</p>
  <p>Please let me know if i'm missing something here.
  Thanks.</p>