无法从 alpine pod 卷曲 redis 服务

cannot curl a redis service from an alpine pod

我有这个 redis 的 yaml 清单

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

我 运行 这个清单和 pod 是 运行ning(没有错误)并且服务是:

$ 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>

为了测试来自另一个 pod 的连接,我创建了一个交互式 pod:

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

我尝试用 curl redis-service:6379 卷曲 redis pod,但返回 curl: (1) Received HTTP/0.9 when not allowed。我试图做 curl -u default:mysecretpassword redis-service:6379 并得到相同的结果。我做了 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

如果我卷曲端点 curl 172.17.0.5:6379 我会得到同样的结果。 pods 都在同一个命名空间中。知道为什么 alpine pod 无法卷曲 redis 服务吗?不太确定能够 curl 服务是否对其他应用程序能够连接到 redis pod 至关重要。

note: the redis.conf has the following changes:

requirepass mysecretpass

# bind 127.0.0.1 //commented

appendonly yes

protected-mode yes

Redis 未使用 HTTP 协议进行客户端连接。所以像 CURL 这样的任何 http 客户端都不能直接与 Redis 服务器通信。

可以使用redis-cli进行测试