2

我有一个 3 节点 Kubernetes 集群,我已经使用 Cass-Operator 在其上设置了 Cassandra。我正在按照这里的说明进行操作 - https://github.com/datastax/cass-operator

以下命令的输出中的 2/2 是什么意思

kubectl get all -n cass-operator
NAME                                READY   STATUS    RESTARTS   AGE
pod/cass-operator-78c6469c6-6qhsb   1/1     Running   0          139m
pod/cluster1-dc1-default-sts-0      2/2     Running   0          138m
pod/cluster1-dc1-default-sts-1      2/2     Running   0          138m
pod/cluster1-dc1-default-sts-2      2/2     Running   0          138m

这是否意味着有 3 个数据中心,每个数据中心运行 2 个 cassandra 节点?应该是因为我的K8S集群只有3个节点。

manuchadha25@cloudshell:~ (copper-frame-262317)$ gcloud compute instances list
NAME                                              ZONE            MACHINE_TYPE   PREEMPTIBLE  INTERNAL_IP  EXTERNAL_IP    STATUS
gke-cassandra-cluster-default-pool-92d544da-6fq8  europe-west4-a  n1-standard-1               10.164.0.26  34.91.214.233  RUNNING
gke-cassandra-cluster-default-pool-92d544da-g0b5  europe-west4-a  n1-standard-1               10.164.0.25  34.91.101.218  RUNNING
gke-cassandra-cluster-default-pool-92d544da-l87v  europe-west4-a  n1-standard-1               10.164.0.27  34.91.86.10    RUNNING

或者 Cassandra-operator 是否在每个 K8S 节点上运行两个容器?

4

1 回答 1

4

当您部署一些应用程序时,一个 pod 内部可以有多个容器。如果你查看Kubernetes Pod 文档,你会发现 2 种类型:

运行单个容器的 Pod。

“每个 Pod 一个容器”模型是最常见的 Kubernetes 用例;在这种情况下,您可以将 Pod 视为单个容器的包装器,Kubernetes 管理 Pod 而不是直接管理容器。

运行多个需要协同工作的容器的 Pod。

Pod 可能封装了一个应用程序,该应用程序由多个位于同一位置的容器组成,这些容器紧密耦合并需要共享资源。这些位于同一位置的容器可能形成一个单一的内聚服务单元——一个容器从共享卷向公众提供文件,而一个单独的“sidecar”容器刷新或更新这些文件。Pod 将这些容器和存储资源包装在一起作为一个可管理的实体。

您可以在此文档中找到更多信息。

Pod可以在此处找到带有 2 个容器的配置 YAML的外观。您可以指定2.spec.containers个或更多容器。

我已经部署了这些 YAML。

$ kubectl get po -n cass-operator
NAME                             READY   STATUS    RESTARTS   AGE
cass-operator-78c9999797-gb88g   1/1     Running   0          4m26s
cluster1-dc1-default-sts-0       2/2     Running   0          4m12s
cluster1-dc1-default-sts-1       2/2     Running   0          4m12s
cluster1-dc1-default-sts-2       2/2     Running   0          4m12s

现在你必须描述 pod。在我的例子中:

$ kubectl describe po cluster1-dc1-default-sts-0 -n cass-operator

Containers:您可以找到图像、端口、状态、挂载等详细信息。

Containers:
  cassandra:
    Container ID:   docker://49b58eacc380da6c29928677e84082373d4330a91c29b29f3f3b021e43c21a38
    Image:          datastax/cassandra-mgmtapi-3_11_6:v0.1.5
    Image ID:       docker-pullable://datastax/cassandra-mgmtapi-3_11_6@sha256:aa7d6072607e60b1dfddd5877dcdf436660bacd31dd4aa6c8c2b85978c9fd170
   ....
  server-system-logger:
    Container ID:  docker://d0b572e767236e2baab7b67d5ad0fc6656b862fc4e463aa1836de80d34f608ea
    Image:         busybox
    Image ID:      docker-pullable://busybox@sha256:2131f09e4044327fd101ca1fd4043e6f3ad921ae7ee901e9142e6e36b354a907
    Port:          <none>

所以这个 pod 运行 2 个容器

  • 姓名:cassandra
  • 姓名:server-system-logger

有 pod with 时1/2怎么办?

这意味着在这个特定的pod只有 1 个容器是running. 容器状态是Waiting和。您可以在此处找到更多信息。RunningTerminated

用例?您可以检查来自指定容器的日志。

$ kubectl logs cluster1-dc1-default-sts-0 -n cass-operator -c cassandra
Starting Management API
/docker-entrypoint.sh: line 74: [: missing `]'
Running java -Xms128m -Xmx128m -jar /opt/mgmtapi/datastax-mgmtapi-server-0.1.0-SNAPSHOT.jar --cassandra-socket /tmp/cassandra.sock --host tcp://0.0.0.0:8080 --host file:///tmp/oss-mgmt.sock --explicit-start true --cassandra-home /var/lib/cassandra/
INFO  [main] 2020-07-03 13:43:08,199 Cli.java:343 - Cassandra Version 3.11.6
INFO  [main] 2020-07-03 13:43:08,709 ResteasyDeploymentImpl.java:551 - RESTEASY002225: Deploying javax.ws.rs.core.Application: class com.datastax.mgmtapi.ManagementApplication
...

或者

$ kubectl logs cluster1-dc1-default-sts-0 -n cass-operator -c server-system-logger
INFO  [main] 2020-07-03 13:44:04,588 YamlConfigurationLoader.java:89 - Configuration location: file:/etc/cassandra/cassandra.yaml
INFO  [main] 2020-07-03 13:44:06,137 Config.java:516 - Node configuration:[allocate_tokens_for_keyspace=null; authenticator=org.apache.cassandra.auth.PasswordAuthenticator; authorizer=org.apache.cassandra.auth.CassandraAuthorizer; auto_bootstrap=true; auto_snapshot=true;
...

您还可以获取此 pod YAML 进行验证。您可以通过以下方式在此示例中执行此操作:

$ kubectl get po cluster1-dc1-default-sts-0 -n cass-operator -o yaml

作为您的问题的补充:

或者 Cassandra-operator 是否在每个 K8S 节点上运行两个容器?

每个 pod 运行两个容器。您可以通过以下方式检查哪个 pod 被调度到哪个节点:

$ kubectl get pods -n cass-operator -o wide
NAME                             READY   STATUS    RESTARTS   AGE   IP          NODE                                       NOMINATED NODE   READINESS GATES
cass-operator-78c9999797-gb88g   1/1     Running   0          20m   10.44.1.4   gke-cluster-2-default-pool-5aa60336-n3hr   <none>           <none>
cluster1-dc1-default-sts-0       2/2     Running   0          19m   10.44.1.5   gke-cluster-2-default-pool-5aa60336-n3hr   <none>           <none>
cluster1-dc1-default-sts-1       2/2     Running   0          19m   10.44.2.3   gke-cluster-2-default-pool-5aa60336-dl2g   <none>           <none>
cluster1-dc1-default-sts-2       2/2     Running   0          19m   10.44.0.9   gke-cluster-2-default-pool-5aa60336-m7ms   <none>           <none>
于 2020-07-03T14:00:35.680 回答