title: Connection refused when trying to access a kubernetes pod via kubernetes DNS
body: <p>I am trying to set up a hadoop single node on kubernetes.
  The odd thing is that, when i login into the pod via <code>kubectl exec -it &lt;pod&gt; /bin/bash</code> i can happily access e.g. the name node on port 9000.</p>
  
  <pre><code>root@hadoop-5dcf94b54d-7fgfq:/hadoop/hadoop-2.8.5# telnet localhost 9000
  Trying 127.0.0.1...
  Connected to localhost.
  Escape character is '^]'.
  </code></pre>
  
  <p>I can also <code>bin/hdfs dfs -put</code> files and such, so the cluster seems to be working fine.
  I can also access the ui via <code>kubectl port-forward &lt;podname&gt; 50070:50070</code> and i see a data node up and running. So the cluster (setup is 'pseudo-distributed' as described <a href="https://hadoop.apache.org/docs/stable/hadoop-project-dist/hadoop-common/SingleCluster.html" rel="nofollow noreferrer">here</a>.) seems to be working fine.</p>
  
  <p>However, when i want to access my service via kubernetes dns, i get a <code>Connection refused</code>.</p>
  
  <pre><code>telnet hadoop.aca534.svc.cluster.local  9000
  Trying 10.32.89.21...
  telnet: Unable to connect to remote host: Connection refused
  </code></pre>
  
  <p><em>What is the difference when accessing a port via k8s-dns?</em></p>
  
  <p>The port must be open, i also can see that hadoop name node is listening on 9000.</p>
  
  <pre><code>lsof -i :9000
  COMMAND  PID USER   FD   TYPE    DEVICE SIZE/OFF NODE NAME
  java    2518 root  227u  IPv4 144574393      0t0  TCP localhost:9000 (LISTEN)
  java    2518 root  237u  IPv4 144586825      0t0  TCP localhost:9000-&gt;localhost:58480 (ESTABLISHED)
  java    2660 root  384u  IPv4 144584032      0t0  TCP localhost:58480-&gt;localhost:9000 (ESTABLISHED)
  </code></pre>
  
  <p>For complete reference here is my kubernetes <code>yml</code> service and deployment specification. </p>
  
  <pre><code>apiVersion: extensions/v1beta1
  kind: Deployment
  metadata:
    labels:
      service: hadoop
    name: hadoop
  spec:
    selector:
      matchLabels:
        service: hadoop
    replicas: 1
    template:
      metadata:
        labels:
          service: hadoop
          run: hadoop
          track: stable
      spec:
        containers:
        - name: hadoop
          image: falcowinkler/hadoop:2.8.5
          imagePullPolicy: Never
          ports:
            # HDFS Ports
            - containerPort: 50010
            - containerPort: 50020
            - containerPort: 50070
            - containerPort: 50075
            - containerPort: 50090
            - containerPort: 8020
            - containerPort: 9000
            # Map Reduce Ports
            - containerPort: 19888
            # YARN Ports
            - containerPort: 8030
            - containerPort: 8031
            - containerPort: 8032
            - containerPort: 8033
            - containerPort: 8040
            - containerPort: 8042
            - containerPort: 8088
            - containerPort: 22
            # Other Ports
            - containerPort: 49707
            - containerPort: 2122
  ---
  apiVersion: v1
  kind: Service
  metadata:
    labels:
      service: hadoop
    name: hadoop
  spec:
    ports:
    - name: hadoop
      port: 9000
    - name: ssh
      port: 22
    - name: hadoop-ui
      port: 50070
    selector:
      service: hadoop
    type: ClusterIP
  </code></pre>