【问题标题】:cannot curl a redis service from an alpine pod [closed]无法从高山 pod 卷曲 redis 服务 [关闭]
【发布时间】:2020-09-24 02:47:46
【问题描述】:

我有这个 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 正在运行(没有错误)并且服务如下:

$ 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,我会得到同样的结果。两个 pod 都在同一个命名空间上。知道为什么 alpine pod 无法卷曲 redis 服务吗?不确定是否能够 curl 服务对于其他应用程序能够连接到 redis pod 是否至关重要。

注意:redis.conf 有以下变化:

requirepass mysecretpass

# bind 127.0.0.1 //已评论

appendonly yes

protected-mode yes

【问题讨论】:

  • 你真的在问为什么redis,有its own protocol,不回复来自curl的HTTP请求?!如果您对“ping-ing”Redis 感兴趣,您可以在自己的代码 sn-p 中看到这种情况,使用 redis-cli ping

标签: kubernetes redis minikube alpine kubernetes-pod


【解决方案1】:

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

你可以使用redis-cli进行测试

【讨论】:

    猜你喜欢
    • 2019-02-16
    • 1970-01-01
    • 2021-12-02
    • 1970-01-01
    • 2020-03-13
    • 2019-06-29
    • 2015-05-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多