[英]Unable to connect to redis cluster on kubernetes from my golang application deployed within the same cluster
I deployed a redis cluster on Kubernetes with bitnami helm charts ( https://github.com/bitnami/charts/tree/master/bitnami/redis-cluster ).我在 Kubernetes 上部署了一个 redis 集群,带有 bitnami helm 图表( https://github.com/bitnami/charts/tree/masterbit/
I can successfully connect to the Redis cluster from within the Kubernetes cluster by running the below commands:我可以通过运行以下命令从 Kubernetes 集群内成功连接到 Redis 集群:
kubectl run my-redis-release-client --rm -it --image docker.io/bitnami/redis:4.0.11-debian-9 -- bash
redis-cli -h redis-cluster-0.redis-cluster-headless.redis
But I am unable to connect to redis cluster from my golang application deployed within the same cluster.但是我无法从部署在同一集群中的 golang 应用程序连接到 redis 集群。
The redis connection string uri I used on my golang application is "redis://redis-cluster-0.redis-cluster-headless.redis:6379".我在 golang 应用程序中使用的 redis 连接字符串 uri 是“redis://redis-cluster-0.redis-cluster-headless.redis:6379”。 This is following the "redis-pod-name.redis-service-name.namespace" convention.
这遵循“redis-pod-name.redis-service-name.namespace”约定。
NOTE: I want to be able to access the redis cluster from only within the Kubernetes cluster.注意:我希望能够仅从 Kubernetes 集群中访问 redis 集群。 I don't want to grant external access.
我不想授予外部访问权限。 Please help...
请帮忙...
Headless
service is if you don't need load-balancing and a single Service IP. Headless
服务是如果您不需要负载平衡和单个服务 IP。 Headless
service is not for accessing the redis cluster from only within the Kubernetes cluster Headless
服务不适用于仅从 Kubernetes 集群内访问 redis 集群
You can create a service to expose redis.您可以创建一个服务来公开 redis。 Below is an example to create a
ClusterIP
type which only let's you connect to it from within the cluster and not from outside the cluster .下面是一个创建
ClusterIP
类型的示例,它只允许您从集群内部而不是从集群外部连接到它。
apiVersion: v1
kind: Service
metadata:
name: redis
namespace: default
spec:
ports:
- port: 6379
targetPort: 6379
selector:
app: redis
The pod or deployment of redis need to have matching label app: redis
redis 的 pod 或部署需要有匹配的 label
app: redis
Then you can connect to it using redis.default.svc.cluster.local:6379
to connect to it from Golang app.然后你可以使用
redis.default.svc.cluster.local:6379
从 Golang 应用程序连接到它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.