我有这个Yaml清单供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
我运行此清单,并且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
,我会得到相同的结果。两个吊舱都在同一名称空间上。知道为什么高山吊舱无法卷曲Redis服务吗?不确定是否可以卷曲服务对于其他应用程序能够连接到Redis Pod是否至关重要。
请注意:
redis.conf
进行了以下更改:
requirepass mysecretpass
# bind 127.0.0.1
//评论
appendonly yes
protected-mode yes
答案 0 :(得分:2)
Redis未使用HTTP协议进行客户端连接。因此,任何HTTP客户端(例如CURL)都无法直接与Redis服务器通信。
您可以使用redis-cli进行测试