通过 GKE 获取 pod 运行 Cassandra 的 shell

get shell of the pod running Cassandra via GKE

我创建了一个CassandraGKE集群,我想运行nodetool在每个节点上备份数据。我不知道该怎么做。

到目前为止,我已经 SSH 连接到 kubernetes 集群上的节点,但从那时起我就丢失了。我做了 docker ps -a 并且可以看到容器。我如何到达每个 container/pod 并返回?

试试这个 article 上的步骤,得到你的 pods:

kubectl get pvc

然后:

kubectl exec cassandra-pod -- nodetool status

用 pod 名称更改 cassandra-pod。

@Manu Chadha

我不确定您使用哪种方法在 GKE 上安装 Cass,但使用 cass-operator 标签我假设您使用的是 Cass Operator。

这就是我到达 pods(需要 POD 名称)的方式:

kubectl -n cass-operator get pods
NAME                             READY   STATUS    RESTARTS   AGE
cass-operator-557f6689df-qftdf   1/1     Running   0          14m
cluster1-dc1-default-sts-0       2/2     Running   0          11m
cluster1-dc1-default-sts-1       2/2     Running   0          11m
cluster1-dc1-default-sts-2       2/2     Running   0          11m

接下来我可以使用 pod 名称到达 bash:

kubectl -n cass-operator exec --stdin cluster1-dc1-default-sts-0 -- /bin/bash

来自 bash 我可以使用 nodetool 或 dsetool

你也可以像这样直接执行这些:

kubectl -n cass-operator exec -it -c cassandra cluster1-dc1-default-sts-0 -- nodetool status

我正在更新以回答关于备份的最后一个问题。使用 cass-operator 进行备份有点不同。请务必在您的 yaml 中包含启用的备份:

# Sized to work on 3 k8s workers nodes with 1 core / 4 GB RAM
# See neighboring example-cassdc-full.yaml for docs for each parameter
apiVersion: cassandra.datastax.com/v1beta1
kind: CassandraDatacenter
metadata:
  name: dc1
spec:
  clusterName: cluster1
  serverType: dse
  serverVersion: "6.8.4"
  managementApiAuth:
    insecure: {}
  size: 3
  storageConfig:
    cassandraDataVolumeClaimSpec:
      storageClassName: server-storage
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 25Gi
  config:
    cassandra-yaml:
      backup_service:
        enabled: true
    jvm-server-options:
      initial_heap_size: "800M"
      max_heap_size: "800M"
      additional-jvm-opts:
        # As the database comes up for the first time, set system keyspaces to RF=3
        - "-Ddse.system_distributed_replication_dc_names=dc1"
        - "-Ddse.system_distributed_replication_per_dc=3"

遵循 GKE 和 Google 博客存储的记录步骤:

https://docs.datastax.com/en/dse/6.8/dse-admin/datastax_enterprise/operations/opsBackupRestoreCreateBackupStore.html

https://docs.datastax.com/en/dse/6.8/dse-admin/datastax_enterprise/operations/opsCqlCreateBackupStore.html