将minikube上的cassandra集群暴露给外部访问

dojqjjoe  于 2021-06-14  发布在  Cassandra
关注(0)|答案(2)|浏览(468)

我正试图在minikube中部署一个cassandra多节点集群,我遵循了这个教程的示例:使用有状态集部署cassandra并做了一些修改,集群已经启动并运行,使用kubectl我可以通过cqlsh连接,但我想从外部连接,我试图通过nodeport公开服务并测试与datastax studio(192.168.99.100:32554)的连接,但没有成功,后来我想在spring boot中连接,我建议必须使用svc名称或节点ip。

  1. All host(s) tried for query failed (tried: /192.168.99.100:32554 (com.datastax.driver.core.exceptions.TransportException: [/192.168.99.100:32554] Cannot connect))

[Cassandra-0]/etc/cassandra/cassandra.yaml

  1. rpc_port: 9160
  2. broadcast_rpc_address: 172.17.0.5
  3. listen_address: 172.17.0.5
  4. # listen_interface: eth0
  5. start_rpc: true
  6. rpc_address: 0.0.0.0
  7. # rpc_interface: eth1
  8. seed_provider:
  9. - class_name: org.apache.cassandra.locator.SimpleSeedProvider
  10. parameters:
  11. - seeds: "cassandra-0.cassandra.default.svc.cluster.local"

这里是svc和pods的minikube输出

  1. $ kubectl cluster-info
  2. Kubernetes master is running at https://192.168.99.100:8443
  3. KubeDNS is running at https://192.168.99.100:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
  4. $ kubectl get svc
  5. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
  6. cassandra NodePort 10.102.236.158 <none> 9042:32554/TCP 20m
  7. kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 22h
  8. $ kubectl get pods -o wide
  9. NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
  10. cassandra-0 1/1 Running 0 20m 172.17.0.4 minikube <none> <none>
  11. cassandra-1 1/1 Running 0 19m 172.17.0.5 minikube <none> <none>
  12. cassandra-2 1/1 Running 1 19m 172.17.0.6 minikube <none> <none>
  13. $ kubectl describe service cassandra
  14. Name: cassandra
  15. Namespace: default
  16. Labels: app=cassandra
  17. Annotations: kubectl.kubernetes.io/last-applied-configuration:
  18. {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"cassandra"},"name":"cassandra","namespace":"default"},"s...
  19. Selector: app=cassandra
  20. Type: NodePort
  21. IP: 10.102.236.158
  22. Port: <unset> 9042/TCP
  23. TargetPort: 9042/TCP
  24. NodePort: <unset> 32554/TCP
  25. Endpoints: 172.17.0.4:9042,172.17.0.5:9042,172.17.0.6:9042
  26. Session Affinity: None
  27. External Traffic Policy: Cluster
  28. Events: <none>
  29. $ kubectl exec -it cassandra-0 -- nodetool status
  30. Datacenter: datacenter1
  31. =======================
  32. Status=Up/Down
  33. |/ State=Normal/Leaving/Joining/Moving
  34. -- Address Load Tokens Owns (effective) Host ID Rack
  35. UN 172.17.0.5 104.72 KiB 256 68.1% 680bfcb9-b374-40a6-ba1d-4bf7ee80a57b rack1
  36. UN 172.17.0.4 69.9 KiB 256 66.5% 022009f8-112c-46c9-844b-ef062bac35aa rack1
  37. UN 172.17.0.6 125.31 KiB 256 65.4% 48ae76fe-b37c-45c7-84f9-3e6207da4818 rack1
  38. $ kubectl exec -it cassandra-0 -- cqlsh
  39. Connected to K8Demo at 127.0.0.1:9042.
  40. [cqlsh 5.0.1 | Cassandra 3.11.4 | CQL spec 3.4.4 | Native protocol v4]
  41. Use HELP for help.
  42. cqlsh>

Cassandra服务.yaml

  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. labels:
  5. app: cassandra
  6. name: cassandra
  7. spec:
  8. type: NodePort
  9. ports:
  10. - port: 9042
  11. selector:
  12. app: cassandra

cassandra-statefulset.yaml文件

  1. apiVersion: apps/v1
  2. kind: StatefulSet
  3. metadata:
  4. name: cassandra
  5. labels:
  6. app: cassandra
  7. spec:
  8. serviceName: cassandra
  9. replicas: 3
  10. selector:
  11. matchLabels:
  12. app: cassandra
  13. template:
  14. metadata:
  15. labels:
  16. app: cassandra
  17. spec:
  18. terminationGracePeriodSeconds: 1800
  19. containers:
  20. - name: cassandra
  21. image: cassandra:3.11
  22. ports:
  23. - containerPort: 7000
  24. name: intra-node
  25. - containerPort: 7001
  26. name: tls-intra-node
  27. - containerPort: 7199
  28. name: jmx
  29. - containerPort: 9042
  30. name: cql
  31. resources:
  32. limits:
  33. cpu: "500m"
  34. memory: 1Gi
  35. requests:
  36. cpu: "500m"
  37. memory: 1Gi
  38. securityContext:
  39. capabilities:
  40. add:
  41. - IPC_LOCK
  42. lifecycle:
  43. preStop:
  44. exec:
  45. command:
  46. - /bin/sh
  47. - -c
  48. - nodetool drain
  49. env:
  50. - name: MAX_HEAP_SIZE
  51. value: 512M
  52. - name: HEAP_NEWSIZE
  53. value: 100M
  54. - name: CASSANDRA_SEEDS
  55. value: "cassandra-0.cassandra.default.svc.cluster.local"
  56. - name: CASSANDRA_CLUSTER_NAME
  57. value: "K8Demo"
  58. - name: CASSANDRA_DC
  59. value: "DC1-K8Demo"
  60. - name: CASSANDRA_RACK
  61. value: "Rack1-K8Demo"
  62. - name: CASSANDRA_START_RPC
  63. value: "true"
  64. - name: CASSANDRA_RPC_ADDRESS
  65. value: "0.0.0.0"
  66. - name: POD_IP
  67. valueFrom:
  68. fieldRef:
  69. fieldPath: status.podIP
  70. # These volume mounts are persistent. They are like inline claims,
  71. # but not exactly because the names need to match exactly one of
  72. # the stateful pod volumes.
  73. volumeMounts:
  74. - name: cassandra-data
  75. mountPath: /var/lib/cassandra
  76. # These are converted to volume claims by the controller
  77. # and mounted at the paths mentioned above.
  78. # do not use these in production until ssd GCEPersistentDisk or other ssd pd
  79. volumeClaimTemplates:
  80. - metadata:
  81. name: cassandra-data
  82. spec:
  83. accessModes: [ "ReadWriteOnce" ]
  84. storageClassName: fast
  85. resources:
  86. requests:
  87. storage: 1Gi
  88. ---
  89. kind: StorageClass
  90. apiVersion: storage.k8s.io/v1
  91. metadata:
  92. name: fast
  93. provisioner: k8s.io/minikube-hostpath
  94. parameters:
  95. type: pd-standard
vnzz0bqm

vnzz0bqm1#

如果我们只想连接cqlsh,您需要的是以下命令

  1. kubectl exec -it cassandra-0 -- cqlsh

另一方面,如果我们想从外部点连接,可以使用命令获取cassandraurl(我使用dbever连接cassandra集群)

  1. minikube service cassandra --url
t98cgbkg

t98cgbkg2#

对于有这个问题的人:在阅读了datastax的文档之后,我意识到datastax studio是为datastax enterprise、本地开发和cassanda社区版而设计的,我使用datastax devcenter,它可以工作。
对于spring引导(在minikube上运行的cassandra集群):

  1. spring.data.cassandra.keyspacename=mykeyspacename
  2. spring.data.cassandra.contactpoints=cassandra-0.cassandra.default.svc.cluster.local
  3. spring.data.cassandra.port=9042
  4. spring.data.cassandra.schemaaction=create_if_not_exists

对于datastax devcenter(在minikube上运行的cassandra群集):

  1. ContactHost = 192.168.99.100
  2. NativeProtocolPort: 300042

更新的cassandra服务

  1. # ------------------- Cassandra Service ------------------- #
  2. apiVersion: v1
  3. kind: Service
  4. metadata:
  5. labels:
  6. app: cassandra
  7. name: cassandra
  8. spec:
  9. type: NodePort
  10. ports:
  11. - port: 9042
  12. nodePort: 30042
  13. selector:
  14. app: cassandra
展开查看全部

相关问题