Kubernetes can't connect redis on Cluster-IP of service

3/5/2018

I got on Google cloud this setup:

  • Pod and service with (php) web app
  • Pod and service with mysql server
  • Pod and service with redis server

Where kubernetes configuration file for mysql server and redis server are almost identical, only what differs is name, port and image.

I can connect mysql server from the web app but I can't connect redis server.

Also I can't connect redis server from web app on its service CLUSTER-IP but I can connect redis server on its pod IP.

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: redis
spec:
  replicas: 1
  selector:
    matchLabels:
      app: redis
  template:
    metadata:
      labels:
        app: redis
    spec:
      containers:
        - name: redis
          image: launcher.gcr.io/google/redis4
          resources:
            requests:
              cpu: 100m
              memory: 100Mi
          ports:
          - containerPort: 6379
          env:
---
apiVersion: v1
kind: Service
metadata:
  name: redis
  labels:
    app: redis
    role: master
    tier: backend
spec:
  selector:
    app: redis
    role: master
    tier: backend
  ports:
  - port: 6379
    targetPort: 6379
-- Andrej Kouril
kubernetes
redis

1 Answer

3/5/2018

The deployment spec is missing some labels so the service is not selecting it.

Current deployment spec:

metadata:
  labels:
    app: redis

include the other labels required by the service:

metadata:
  labels:
    app: redis  
    role: metadata  
    tier: backend  

or depending on how you want to look at it the service spec is trying match labels that don't exist, you can change the service from:

  selector:
    app: redis
    role: master
    tier: backend

to:

selector:
    app: redis
-- stacksonstacks
Source: StackOverflow