简体   繁体   English

无法从部署在同一集群中的我的 golang 应用程序连接到 kubernetes 上的 redis 集群

[英]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 集群:

  1. kubectl run my-redis-release-client --rm -it --image docker.io/bitnami/redis:4.0.11-debian-9 -- bash

  2. 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.

相关问题 Kubernetes - 无法从 Kubernetes 集群内部连接到 Redis Pod - Kubernetes - Unable to connect to Redis Pods from inside Kubernetes Cluster 无法连接到部署在 kubernetes 集群上的服务器 - Cannot connect to the server deployed on kubernetes cluster 将 Python 应用程序连接到 Kubernetes 集群上的 Redis - Connect Python app to Redis on Kubernetes cluster 如何从运行在同一 Kube.netes 集群中的容器连接到 Docker,它在 Kube.netes 集群中的主机虚拟机上运行? - How do I connect to Docker, running on host VMs in a Kubernetes cluster from a container running in the same Kubernetes cluster? 在部署在 Kubernetes 集群上的容器化 Python 应用程序中,我应该指向哪个 IP 地址? - What IP Address should I point to in my containerized Python application that is deployed on a Kubernetes cluster? 如何从运行在同一集群上的节点内的容器化应用程序访问 Kubernetes 集群? - How to get access to kubernetes cluster from containerized application running inside node hosted on same cluster? 无法从 docker 容器连接到 redis 集群 - Not able to connect to redis cluster from docker container 如何测试在kubernetes集群上部署为pod的nodejs应用程序? - how to test nodejs application which is deployed as a pod on kubernetes cluster? 从部署它的 kubernetes 集群中使用 docker 注册表 - Use a docker registry from the kubernetes cluster on which it is deployed 从本地开发 kubernetes 集群中的 pod 内连接到 docker compose 服务的最佳便携方式 - Best portable way to connect from within a pod in a local dev kubernetes cluster to docker compose service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM