Andrej Kouril
Andrej Kouril

Reputation: 303

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

I got on Google cloud this setup:

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

Upvotes: 0

Views: 2713

Answers (1)

stacksonstacks
stacksonstacks

Reputation: 9321

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

Upvotes: 5

Related Questions