<p>I created a redis deployment and service in kubernetes,
I can access redis from another pod by service ip, but I can't access it by service name</p>
<p>the redis yaml</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis-deployment
  namespace: myapp-ns
spec:
  replicas: 1
  selector:
    matchLabels:
      component: redis
  template:
    metadata:
      labels:
        component: redis
    spec:
      containers:
        - name: redis
          image: redis
          ports:
            - containerPort: 6379
---
apiVersion: v1
kind: Service
metadata:
  name: redis
  namespace: myapp-ns
spec:
  type: ClusterIP
  selector:
    component: redis
  ports:
    - port: 6379
      targetPort: 6379
</code></pre>

user897645
<p>I applied your file, and I am able to ping and telnet to the service both from within the same namespace and from a different namespace.  To test this, I created pods in the same namespace and in a different namespace and installed telnet and ping.  Then I exec'ed into them and did the below tests:</p>
<p><em>Same Namespace</em></p>
<pre><code>kubectl exec -it &lt;same-namespace-pod&gt; /bin/bash
# ping redis
PING redis.&lt;redis-namespace&gt;.svc.cluster.local (172.20.211.84) 56(84) bytes of data.

# telnet redis 6379
Trying 172.20.211.84...
Connected to redis.&lt;redis-namespace&gt;.svc.cluster.local.
Escape character is '^]'.
</code></pre>
<p><em>Different Namespace</em></p>
<pre><code>kubectl exec -it &lt;different-namespace-pod&gt; /bin/bash
# ping redis.&lt;redis-namespace&gt;.svc.cluster.local
PING redis.test.svc.cluster.local (172.20.211.84) 56(84) bytes of data.

# telnet redis.&lt;redis-namespace&gt;.svc.cluster.local 6379
Trying 172.20.211.84...
Connected to redis.&lt;redis-namespace&gt;.svc.cluster.local.
Escape character is '^]'.
</code></pre>
<p>If you are not able to do that due to dns resolution issues, you could look at your <code>/etc/resolv.conf</code> in your pod to make sure it has the search prefixes <code>svc.cluster.local</code> and <code>cluster.local</code></p>
