<p>I set up a simple redis ClusterIP service to be accessed by a php LoadBalancer service inside the Cluster. The php log shows the connection timeout error. The redis service is not accessible. </p>

<pre><code>'production'.ERROR: Operation timed out {"exception":"[object] (RedisException(code: 0): 
Operation timed out at /var/www/html/vendor/laravel/framework/src/Illuminate/Redis
/html/vendor/laravel/framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php(109): 
    Redis-&gt;connect('redis-svc', '6379', 0, '', 0, 0)
</code></pre>

<p>My redis service is quite simple so I don't know what went wrong:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    io.kompose.service: redis
  name: redis
spec:
  replicas: 1
  strategy: {}
  template:
    metadata:
      labels:
        io.kompose.service: redis
    spec:
      containers:
      - image: redis:alpine
        name: redis
        resources: {}
        ports:
        - containerPort: 6379
      restartPolicy: Always
status: {}
---
kind: Service
apiVersion: v1
metadata:
  name: redis-svc
spec:
  selector:
    app: redis
  ports:
  - protocol: TCP
    port: 6379
    targetPort: 6379
  type: ClusterIP
</code></pre>

<p>I verify redis-svc is running, so why it can't be access by other service</p>

<pre><code>kubectl get service redis-svc                                                                                                                                  git:k8s*
NAME        TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
redis-svc   ClusterIP   10.101.164.225   &lt;none&gt;        6379/TCP   22m
</code></pre>

<p>This SO <a href="https://stackoverflow.com/questions/50852542/kubernetes-cannot-ping-another-service/50853306">kubernetes cannot ping another service</a> said ping doesn't work with service's cluster IP(indeed) how do I verify whether redis-svc can be accessed or not ?</p>

<p>---- update ----</p>

<p>My first question was a silly mistake but I still don't know how do I verify whether the service can be accessed or not (by its name). For example I changed the service name to be the same as the deployment name and I found php failed to access redis again.</p>

<p><code>kubectl get endpoints</code> did not help now.</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: redis
...
status: {}
---
kind: Service
apiVersion: v1
metadata:
  name: redis
...
</code></pre>

<p>my php is another service with env set the redis's service name</p>

<pre><code>spec:
  containers:
  - env:
    - name: REDIS_HOST # the php code access this variable
      value: redis-svc #changed to "redis" when redis service name changed to "redis"
</code></pre>

<p>----- update 2------ </p>

<p>The reason I can' set my redis service name to "redis" is b/c "<a href="https://kubernetes.io/docs/concepts/services-networking/service/#environment-variables" rel="nofollow noreferrer">kubelet adds a set of environment variables for each active Service</a>" so with the name "redis", there will be a <code>REDIS_PORT=tcp://10.101.210.23:6379</code> which overwrite my own <code>REDIS_PORT=6379</code>
But my php just expect the value of REDIS_PORT to be 6379</p>

Qiulang
<p>I ran the yaml configuration given by you and it created the deployment and service. However when I run the below commands:</p>

<pre class="lang-sh prettyprint-override"><code>&gt;&gt;&gt; kubectl get svc
NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
kubernetes   ClusterIP   10.96.0.1       &lt;none&gt;        443/TCP    5d14h
redis-svc    ClusterIP   10.105.31.201   &lt;none&gt;        6379/TCP   109s

&gt;&gt;&gt;&gt; kubectl get endpoints
NAME         ENDPOINTS             AGE
kubernetes   192.168.99.116:8443   5d14h
redis-svc    &lt;none&gt;                78s
</code></pre>

<p>As you see, the endpoints for redis-svc is none, it means that the service doesn't have an endpoint to connect to. You are using selector labels as <code>app: redis</code> in the redis-svc. But <strong>the pods doesn't have the selector label defined in the service.</strong> Adding the label <code>app: redis</code> to the pod template will work. The complete working yaml configuration of deployment will look like:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    io.kompose.service: redis
  name: redis
spec:
  replicas: 1
  strategy: {}
  template:
    metadata:
      labels:
        io.kompose.service: redis
        app: redis
    spec:
      containers:
      - image: redis:alpine
        name: redis
        resources: {}
        ports:
        - containerPort: 6379
      restartPolicy: Always
status: {}
</code></pre>
