<p>I am using below manifest. I am having a simple server which prints pod name on <code>/hello</code>. Here, I was going through kubernetes documentation and it mentioned that we can access service via service name as well. But that is not working for me. As this is a service of type <code>NodePort</code>, I am able to access it using IP of one of the nodes. Is there something wrong with my manifest?</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: myhttpserver
  labels:
    day: zero
    name: httppod
spec:
  replicas: 1
  selector:
    matchLabels:
      name: httppod
      day: zero
  template:
    metadata:
      labels:
        day: zero
        name: httppod
    spec:
      containers:
        - name: myappcont
          image: agoyalib/trial:tryit
          imagePullPolicy: IfNotPresent
---
apiVersion: v1
kind: Service
metadata:
  name: servit
  labels:
    day: zeroserv
spec:
  type: NodePort
  selector:
    day: zero
    name: httppod
  ports:
    - name: mine
      port: 8080
      targetPort: 8090
</code></pre>

<p>Edit: I created my own mini k8s cluster and I am doing these operations on the master node.</p>

Aakash Goyal
<p>From what I understand when you say </p>

<blockquote>
  <p>As this is a service of type NodePort, I am able to access it using IP of one of the nodes</p>
</blockquote>

<p>You're accessing your service from outside your cluster. That's why you can't access it using its name.</p>

<p>To access a service using its name, you need to be inside the cluster.</p>

<p>Below is an example where you use a pod based on centos in order to connect to your service using its name :</p>

<pre class="lang-sh prettyprint-override"><code># Here we're just creating a pod based on centos
$ kubectl run centos --image=centos:7 --generator=run-pod/v1 --command sleep infinity

# Now let's connect to that pod 
$ kubectl exec centos -ti bash
[root@centos /]# curl servit:8080/hello
</code></pre>
