当您部署一些应用程序时,一个 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
和。您可以在此处找到更多信息。Running
Terminated
用例?您可以检查来自指定容器的日志。
$ 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>