Search code examples
kubernetesredisminikubealpine-linuxkubernetes-pod

cannot curl a redis service from an alpine pod


I have this yaml manifest for redis

apiVersion: v1
kind: Pod
metadata:
  name: redis-pod
  namespace: redis-namespace
  labels:
    app: redis
spec:
  containers:
  - name: redis-cntr
    image: redis
    imagePullPolicy: IfNotPresent
    ports:
    - name: redis-port
      containerPort: 6379
    envFrom:
    - secretRef:
        name: redis-secret
    command:
    - redis-server
    readinessProbe:
      exec:
        command:
        - redis-cli
        - ping
      initialDelaySeconds: 3
      periodSeconds: 10
      timeoutSeconds: 1
      successThreshold: 1
      failureThreshold: 3
    volumeMounts:
    - name: redis-vol
      mountPath: /data
    - name: config
      mountPath: /usr/local/etc/redis
  volumes:
  - name: redis-vol
    emptyDir: {}
  - name: config
    configMap:
      name: redis-config
      items:
      - key: redis-config
        path: redis.conf

---
apiVersion: v1
kind: Service
metadata:
  name: redis-service
  namespace: redis-namespace
spec:
  type: ClusterIP
  selector:
    app: redis
  ports:
  - name: redis-srv-port
    port: 6379
    targetPort: redis-port
    protocol: TCP

I run this manifest and the pod is running (no errors) and the service is as:

$ kubectl describe service redis-service
Name:              redis-service
Namespace:         redis-namespace
Labels:            <none>
Annotations:       Selector:  app=redis
Type:              ClusterIP
IP:                10.107.206.191
Port:              redis-srv-port  6379/TCP
TargetPort:        redis-port/TCP
Endpoints:         172.17.0.5:6379
Session Affinity:  None
Events:            <none>

To test the connection from another pod I create an interactive pod:

$ kubectl run -it alpine --image=alpine --restart=Never -- /bin/sh

I try to curl the redis pod with curl redis-service:6379 but the is returned curl: (1) Received HTTP/0.9 when not allowed. I have attempted to do curl -u default:mysecretpassword redis-service:6379 and get the same results. I do a nslookup:

$ / # nslookup redis-service
Server:     10.96.0.10
Address:    10.96.0.10:53

Name:   redis-service.redis-namespace.svc.cluster.local
Address: 10.107.206.191

If I curl the endpoints curl 172.17.0.5:6379 I get the same thing. Both pods are on the same namespace. Any idea why the alpine pod unable to curl the redis-service? Not really sure if being able to curl the service is crucial for other applications to be able to connect to the redis pod.

note: the redis.conf has the following changes:

requirepass mysecretpass

# bind 127.0.0.1 //commented

appendonly yes

protected-mode yes


Solution

  • Redis is not using HTTP protocol for client connection. So any http client like CURL cannot directly communicate with Redis server.

    You can use redis-cli for testing