公开在Kubernetes上运行的Cassandra
我正在Kubernetes上运行Cassandra(3个实例),并想将其暴露给外部,我的应用程序还没有在Kubernetes中。 所以我策划了一个负载平衡的服务,如下所示:
apiVersion: v1 kind: Service metadata: namespace: getquanty labels: app: cassandra name: cassandra annotations: kubernetes.io/tls-acme: "true" spec: clusterIP: ports: - port: 9042 name: cql nodePort: 30001 - port: 7000 name: intra-node nodePort: 30002 - port: 7001 name: tls-intra-node nodePort: 30003 - port: 7199 name: jmx nodePort: 30004 selector: app: cassandra type: LoadBalancer
这是结果是:
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE cassandra 10.55.249.88 GIVEN_IP_GCE_LB 9042:30001/TCP,7000:30002/TCP,7001:30003/TCP,7199:30004/TCP 26m
我能够使用sh(cqlsh GIVEN_IP_GCE_LB)连接,但是当我尝试添加数据到Cassandra使用节点datastax驱动程序,我得到这个:
message: 'Cannot achieve consistency level SERIAL', info: 'Represents an error message from the server', code: 4096, consistencies: 8, required: 1, alive: 0, coordinator: '35.187.166.68:9042' }, '10.52.4.32:9042': 'Host considered as DOWN', '10.52.2.15:9042': 'Host considered as DOWN' }, info: 'Represents an error when a query cannot be performed because no host is available or could be reached by the driver.', message: 'All host(s) tried for query failed. First host tried, 35.187.166.68:9042: ResponseError: Cannot achieve consistency level SERIAL. See innerErrors.' }
我的第一个,但我也需要暴露其他端口,所以我做了(节点内,TLS的内部节点,JMX),但它是同样的错误。
Kubernetes给你访问代理,我试图代理从我的机器使用构build的网站的pod来testing,如果我有访问,但我不能使用cqlsh连接:
http://127.0.0.1:8001/api/v1/namespaces/qq/pods/cassandra-0:cql/proxy
我没有想法,剩下的一件事就是公开每一个非常丑陋的实例(为每个实例提供一个服务),但是在我将应用程序迁移到Kubernetes之前,它会让我连接到外部的节点。
有没有人有想法如何揭露Cassandra节点到互联网,使Datastax驱动程序知道所有的节点? 感谢您的时间。
经过更多的阅读后,我发现复制策略是导致问题的原因,NetworkStrategy适用于多集群,我有一个,所以我改变了复制到简单的节点的数量,现在每件事情都按预期工作。
您需要为您创build的复制控制器使用无头服务。
你的服务应该是这样的:
apiVersion: v1 kind: Service metadata: labels: app: cassandra name: cassandra spec: clusterIP: None ports: - port: 9042 selector: app: cassandra
此外,你可以参考下面的链接,并调出一个cassandra集群。 https://github.com/kubernetes/kubernetes/tree/master/examples/storage/cassandra
我build议通过复制控制器或statefulset或daemonset运行cassandra pod,因为这样kubernetes可以根据需要pipe理pod的重新启动/重新计划。