[英]redis cluster K8S connection
I'm running a redis-cluster in K8S: 我在K8S中运行redis集群:
kubectl get services -o wide
redis-cluster ClusterIP 10.97.31.167 <none> 6379/TCP,16379/TCP 22h app=redis-cluster
When connecting to the cluster IP from the node itself connection is working fine: 从节点本身连接到群集IP时,连接工作正常:
redis-cli -h 10.97.31.167 -c
10.97.31.167:6379> set some_val 1
-> Redirected to slot [11662] located at 10.244.1.9:6379
OK
Simple forwarding to the remote machine won't work: 简单转发到远程计算机将不起作用:
devvm:ssh -L 6380:10.97.31.167:6379 -i user.pem admin@k8snode.com
On dev VM: 在开发VM上:
root@devvm:~# redis-cli -h 127.0.0.1 -p 6380 -c
127.0.0.1:6380> set jaheller 1
-> Redirected to slot [11662] located at 10.244.1.9:6379
The redis connection is timeouting at this point. Redis连接此时超时。
I belive in all scenarios you just need to expose the service using kubernetes Service object of type: 我相信在所有情况下,您只需要使用kubernetes类型的Service对象公开服务即可:
Cluster IP ( in case you are consuming it inside the cluster ) 群集IP (以防您在群集内部使用它)
NodePort ( for external access ) NodePort (用于外部访问)
LoadBalancer ( in case of public access and if you are on cloud provider) LoadBalancer (如果具有公共访问权限,并且您在云提供商上)
NodePort with external loadbalancer ( for public external access if you are on local infrastructure ) 带有外部负载平衡器的NodePort(如果您在本地基础架构上,则用于公共外部访问)
Dont need to worry about individual pods. 无需担心单个吊舱。 The Service will take care of them. 服务将照顾他们。
Docs: 文档:
https://kubernetes.io/docs/concepts/services-networking/service/ https://kubernetes.io/docs/concepts/services-networking/service/
I don't think you need any port redirection. 我认为您不需要任何端口重定向。 You have to build an ingress controller upon your cluster though, ie nginx ingress controller 不过,您必须在集群上构建一个入口控制器,即nginx入口控制器
Then you just set up a single ingress service with exposed access, which will serve a cluster traffic. 然后,您只需设置具有公开访问权限的单个入口服务即可为群集流量提供服务。
Here is an example of Ingress Controller to Access cluster service: 这是Ingress Controller访问群集服务的示例:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: redis-cluster-ing
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- http:
paths:
- backend:
serviceName: redis-cluster
servicePort: 6379
You may check a step-by-step instruction 您可以查看分步说明
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.