本文介绍了如何从集群外部访问我的Cassandra/Kubernetes集群?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始使用Cass-Operator,并且安装过程像个魅力! https://github.com/datastax/cass-operator .

I have started using Cass-Operator and the setup worked like a charm! https://github.com/datastax/cass-operator.

但是我有一个问题.我的集群已启动并在GCP上运行.但是,如何从笔记本电脑(基本上是从外部)访问它?抱歉,我是Kubernetes的新手,所以我不知道如何从外部访问集群?

I have an issue though. My cluster is up and running on GCP. But how do I access it from my laptop (basically from outside)? Sorry, I'm new to Kubernetes so I do not know how to access the cluster from outside?

我可以看到GCP仪表板上的节点都在上面.我可以从笔记本电脑ping节点的外部IP,但是当我运行cqlsh external_ip 9042时,连接将失败.

I can see the nodes are up on the GCP dashboard. I can ping the external IP of the nodes from my laptop but when I run cqlsh external_ip 9042 then the connection fails.

如何将K8s/Cassandra群集连接到外部工作,以便我的Web应用程序可以访问它?

How do I go about connecting the K8s/Cassandra cluster to outside work so that my web application can access it?

我想:

  1. 具有一个URL,以便我的Web应用程序使用该URL而不是IP地址来连接到cassandra/K8s集群.因此,我需要一个DNS. K8S是否默认提供它?会是网址吗?在某些节点中为我管理dns映射的K8会重启吗?
  2. 我的Web应用程序应该能够在9042上访问Cassandra.似乎已经为http/https完成了负载平衡.该Cassandra应用程序不是http/https请求.所以我不需要端口80或443

我已经阅读了一些有关Service,Loadbalancer和Ingress的教​​程.但是我无法开始.

I have read few tutorials which talk about Service, Loadbalancer and Ingress. But I am unable to make a start.

我创建了这样的服务

kind: Service
apiVersion: v1
metadata:
  name: cass-operator-service
spec:
  type: LoadBalancer
  ports:
    - port: 9042
  selector:
    name: cass-operator

然后创建服务-kubectl apply -f ./cass-operator-service.yaml

我检查了服务是否使用kubectl get svc创建并获得了输出

I checked if the service was created using kubectl get svc and got output

NAME                    TYPE           CLUSTER-IP      EXTERNAL-IP     PORT(S)          AGE
cass-operator-service   LoadBalancer   10.51.249.224   34.91.214.233   9042:30136/TCP   4m17s
kubernetes              ClusterIP      10.51.240.1     <none>          443/TCP          10h.

但是当我运行cqlsh 34.91.214.233 9042时,连接失败

But when I run cqlsh 34.91.214.233 9042 then the connection fails

似乎将端口9042的请求转发到30136.但是应该将它们转发到9042,因为那是Pod中的Cassandra映像侦听传入请求的地方

It seems that the requests to port 9042 would be forwarded to 30136. But They should be forwarded to 9042 as that is where the Cassandra image in the pods is listening for incoming requests

更新

尝试了targetPort但还是没有运气

Tried targetPort but still no luck

manuchadha25@cloudshell:~ (copper-frame-262317)$ cat cass-operator-service.yaml
kind: Service
apiVersion: v1
metadata:
  name: cass-operator-service
spec:
  type: LoadBalancer
  ports:
    - port: 9042
      targetPort: 9042
  selector:
    name: cass-operator
manuchadha25@cloudshell:~ (copper-frame-262317)$ kubectl get service
NAME         TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.51.240.1   <none>        443/TCP   11h
manuchadha25@cloudshell:~ (copper-frame-262317)$ kubectl apply -f ./cass-operator-service.yaml
service/cass-operator-service created
manuchadha25@cloudshell:~ (copper-frame-262317)$ kubectl get service
NAME                    TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
cass-operator-service   LoadBalancer   10.51.255.184   <pending>     9042:30024/TCP   12s
kubernetes              ClusterIP      10.51.240.1     <none>        443/TCP          11h
manuchadha25@cloudshell:~ (copper-frame-262317)$ kubectl get service
NAME                    TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
cass-operator-service   LoadBalancer   10.51.255.184   <pending>     9042:30024/TCP   37s
kubernetes              ClusterIP      10.51.240.1     <none>        443/TCP          11h
manuchadha25@cloudshell:~ (copper-frame-262317)$ kubectl get service
NAME                    TYPE           CLUSTER-IP      EXTERNAL-IP     PORT(S)          AGE
cass-operator-service   LoadBalancer   10.51.255.184   34.91.214.233   9042:30024/TCP   67s
kubernetes              ClusterIP      10.51.240.1     <none>          443/TCP          11h
manuchadha25@cloudshell:~ (copper-frame-262317)$ ping 34.91.214.233
PING 34.91.214.233 (34.91.214.233) 56(84) bytes of data.
64 bytes from 34.91.214.233: icmp_seq=1 ttl=109 time=7.89 ms

查询所有名称空间将显示以下内容

Querying all names spaces reveal the following

但是使用命名空间cass-operator查询pod会返回空结果

But querying pods with namespace cass-operator returns empty result

manuchadha25@cloudshell:~ (copper-frame-262317)$ kubectl get pods -l name=cass-operator
No resources found in default namespace.

推荐答案

08-23 06:00