我正在尝试使用centos上的kubernetes创建redis集群.我让我的kubernetes master在一个主机上运行,而kubernetes slave在两个不同的主机上运行.
etcdctl get /kube-centos/network/config
{ "Network": "172.30.0.0/16", "SubnetLen": 24, "Backend": { "Type": "vxlan" } }
这是我的复制控制器
apiVersion: v1
kind: ReplicationController
metadata:
name: redis-master
labels:
app: redis
role: master
tier: backend
spec:
replicas: 6
template:
metadata:
labels:
app: redis
role: master
tier: backend
spec:
containers:
- name: master
image: redis
command:
- "redis-server"
args:
- "/redis-master/redis.conf"
ports:
- containerPort: 6379
volumeMounts:
- mountPath: /redis-master
name: config
- mountPath: /redis-master-data
name: data
volumes:
- name: data
emptyDir: {}
- name: config
configMap:
name: redis-config
items:
- key: redis-config
path: redis.conf
kubectl create -f rc.yaml
NAME READY STATUS RESTARTS AGE IP NODE
redis-master-149tt 1/1 Running 0 8s 172.30.96.4 centos-minion-1
redis-master-14j0k 1/1 Running 0 8s 172.30.79.3 centos-minion-2
redis-master-3wgdt 1/1 Running 0 8s 172.30.96.3 centos-minion-1
redis-master-84jtv 1/1 Running 0 8s 172.30.96.2 centos-minion-1
redis-master-fw3rs 1/1 Running 0 8s 172.30.79.4 centos-minion-2
redis-master-llg9n 1/1 Running 0 8s 172.30.79.2 centos-minion-2
使用Redis-config文件
appendonly yes
cluster-enabled yes
cluster-config-file /redis-master/nodes.conf
cluster-node-timeout 5000
dir /redis-master
port 6379
我使用以下命令来创建kubernetes服务.
kubectl expose rc redis-master –name=redis-service –port=6379 –target-port=6379 –type=NodePort
Name: redis-service
Namespace: default
Labels: app=redis
role=master
tier=backend
Selector: app=redis,role=master,tier=backend
Type: NodePort
IP: 10.254.229.114
Port: <unset> 6379/TCP
NodePort: <unset> 30894/TCP
Endpoints: 172.30.79.2:6379,172.30.79.3:6379,172.30.79.4:6379 + 3 more...
Session Affinity: None
No events.
现在我已经启动并运行了所有pod和服务.我正在使用redis-trib pod来创建redis集群.
kubectl exec -it redis-trib bash
./redis-trib.rb create –replicas 1 172.30.79.2:6379 172.30.79.3:6379 172.30.79.4:6379 172.30.96.2:6379 172.30.96.3:6379 172.30.96.4:6379
使用以下消息按预期创建Redis群集.
[OK] All 16384 slots covered.
现在,我应该可以从网络中的任何主机访问kubernetes节点IP(192.168.240.116)和nodePort(30894)上的redis-cluster.当我从其中一个kubernetes节点执行以下命令时,一切都按预期工作.
redis-cli -p 30894 -h 192.168.240.116 -c
192.168.240.116:30894> set foo bar
-> Redirected to slot [12182] located at 172.30.79.4:6379
OK
172.30.79.4:6379>
当我从同一网络中的不同(非kubernetes)节点运行相同的命令时,我看到连接的超时错误.
redis-cli -c -p 30894 -h 192.168.240.116
192.168.240.116:30894> set foo bar
-> Redirected to slot [12182] located at 172.30.79.4:6379
Could not connect to Redis at 172.30.79.4:6379: Connection timed out
使用NodePort服务类型公开时,是否无法访问kubernetes集群网络外的redis-cluster?
此外,我不能使用LoadBalancer服务类型,因为我没有在云上托管它.
我一直坚持这个问题.有人可以建议我应该使用什么方法来访问我网络外的redis-cluster?
谢谢
最佳答案 运行./redis-trib.rb创建–replicas 1 172.30.79.2:6379 172.30.79.3:6379 172.30.79.4:6379 172.30.96.2:6379 172.30.96.3:6379 172.30.96.4:6379对此没有意义建立.
端口6379只能通过您提供的服务访问,但不能直接尝试.这就是您尝试使用设置时遇到问题的原因.
你可以做的是用它自己的服务公开每个POD,并有一个额外的集群服务来加载外部请求.如example repository from Kelsey Hightower所示.这样POD可以通过内部公开的端口进行通信,而(外部)客户端可以使用负载均衡的集群端口.这意味着每个POD都需要它自己的ReplicaSet(或部署). Kelsey在YouTube上提供了长篇演讲,解释了设置 – YouTube/Slideshare.
另一种方法是使用单个redis master,如其他示例所示.