我正在尝试部署一个redis pod,以允许我的暂存应用程序连接到它(以避免在暂存env中使用redis托管服务)。
我使用谷歌云平台和gke,所以管理k8s集群。。。
但是,当我尝试建立连接(从另一个redis pod仅用于测试)时,我收到以下消息:
Could not connect to Redis at redis-cip.redis.svc.cluster.local:6379: Connection refused
我用来做测试的命令是:
redis-cli -h redis-cip.redis.svc.cluster.local -p 6379
url由以下内容组成:
redis-cip:是我用来连接我的redis pod的服务集群
redis:是承载redis pod的命名空间
此外,我使用了redis配置,正如在stackoverflow的一些问题中已经提到的:
protected-mode no
maxmemory 32mb
maxmemory-policy allkeys-lru
随附完整的k8sMap:
配置Map:
apiVersion: v1
kind: ConfigMap
metadata:
name: redis-configmap
namespace: redis
data:
redis.conf: |
protected-mode no
maxmemory 32mb
maxmemory-policy allkeys-lru
redis部署:
apiVersion: v1
kind: Pod
metadata:
name: redis
namespace: redis
spec:
containers:
- name: redis
image: redis
command:
- redis-server
- /usr/local/etc/redis/redis.conf
env:
- name: MASTER
value: "true"
ports:
- containerPort: 6379
volumeMounts:
- mountPath: /redis-master-data
name: data
- mountPath: /usr/local/etc/redis/
name: redis-configmap
resources:
requests:
memory: {{ .Values.resources.requests.memory }}
cpu: {{ .Values.resources.requests.cpu }}
limits:
memory: {{ .Values.resources.limits.memory }}
cpu: {{ .Values.resources.limits.cpu }}
volumes:
- name: data
emptyDir: {}
- name: redis-configmap
configMap:
name: redis-configmap
群集服务:
apiVersion: v1
kind: Service
metadata:
name: redis-cip
namespace: redis
labels:
app: redis
spec:
ports:
- port: 6379
targetPort: 6379
selector:
app: redis
type: ClusterIP
1条答案
按热度按时间hrirmatl1#
连接被拒绝,因为没有带标签的pod
app:redis
. 在你的pod上添加与服务相同的标签spec.selector
```apiVersion: v1
kind: Pod
metadata:
name: redis
namespace: redis
labels:
app:redis
spec:
containers:
- name: redis
image: redis