Timescale Cloud:性能、规模、企业级

自托管产品

MST

您可以使用 TimescaleDB Docker 容器镜像在 Kubernetes 中运行 TimescaleDB。

开发和生产环境

以下说明适用于开发和测试安装。对于生产环境,我们强烈建议您实施以下功能,其中许多可以通过 PostgreSQL 工具实现。

  • 增量备份和数据库快照,以及高效的时间点恢复。
  • 高可用性复制,理想情况下节点分布在多个可用区。
  • 自动故障检测和快速重启,适用于非复制和复制部署。
  • 异步副本,用于在需要时扩展读取。
  • 连接池器,用于扩展客户端连接。
  • 零停机时间的小版本和扩展升级。
  • 分叉工作流,用于主要版本升级和其他功能测试。
  • 监控和可观测性。

部署用于生产环境?使用 Timescale Cloud 服务,我们将为您的数据库进行性能调优,并处理可扩展性、高可用性、备份和管理,让您高枕无忧。

免费试用

若要按照本页面上的步骤操作

在 Kubernetes 上运行 TimescaleDB 与运行 PostgreSQL 类似。本过程概述了非分布式系统的步骤。

将 Kubernetes 集群连接到集群中运行的自托管 TimescaleDB

  1. 为 Timescale 组件创建默认命名空间

    1. 创建 Timescale 命名空间

      kubectl create namespace timescale
    2. 将此命名空间设置为您会话的默认命名空间

      kubectl config set-context --current --namespace=timescale

    有关更多信息,请参阅 Kubernetes 命名空间

  2. 设置持久卷声明 (PVC) 存储

    要为自托管 Kubernetes 手动设置持久卷和声明,请运行以下命令

    kubectl apply -f - <<EOF
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
    name: timescale-pvc
    spec:
    accessModes:
    - ReadWriteOnce
    resources:
    requests:
    storage: 10Gi
    EOF
  3. 将 TimescaleDB 部署为 StatefulSet

    默认情况下,您在 Kubernetes 上安装的 Timescale Docker 镜像 使用默认的 PostgreSQL 数据库、用户和密码。要在 Kubernetes 上部署 TimescaleDB,请运行以下命令

    kubectl apply -f - <<EOF
    apiVersion: apps/v1
    kind: StatefulSet
    metadata:
    name: timescaledb
    spec:
    serviceName: timescaledb
    replicas: 1
    selector:
    matchLabels:
    app: timescaledb
    template:
    metadata:
    labels:
    app: timescaledb
    spec:
    containers:
    - name: timescaledb
    image: 'timescale/timescaledb:latest-pg17'
    env:
    - name: POSTGRES_USER
    value: postgres
    - name: POSTGRES_PASSWORD
    value: postgres
    - name: POSTGRES_DB
    value: postgres
    - name: PGDATA
    value: /var/lib/postgresql/data/pgdata
    ports:
    - containerPort: 5432
    volumeMounts:
    - mountPath: /var/lib/postgresql/data
    name: timescale-storage
    volumes:
    - name: timescale-storage
    persistentVolumeClaim:
    claimName: timescale-pvc
    EOF
  4. 通过在 Kubernetes 中公开 TimescaleDB 允许应用程序连接

    kubectl apply -f - <<EOF
    apiVersion: v1
    kind: Service
    metadata:
    name: timescaledb
    spec:
    selector:
    app: timescaledb
    ports:
    - protocol: TCP
    port: 5432
    targetPort: 5432
    type: ClusterIP
    EOF
  5. 创建 Kubernetes secret 以存储数据库凭据

    kubectl create secret generic timescale-secret \
    --from-literal=PGHOST=timescaledb \
    --from-literal=PGPORT=5432 \
    --from-literal=PGDATABASE=postgres \
    --from-literal=PGUSER=postgres \
    --from-literal=PGPASSWORD=postgres
  6. 部署连接到 TimescaleDB 的应用程序

    kubectl apply -f - <<EOF
    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: timescale-app
    spec:
    replicas: 1
    selector:
    matchLabels:
    app: timescale-app
    template:
    metadata:
    labels:
    app: timescale-app
    spec:
    containers:
    - name: timescale-container
    image: postgres:latest
    envFrom:
    - secretRef:
    name: timescale-secret
    EOF
  7. 测试数据库连接

    1. 创建并运行一个 Pod,使用保存在 timescale-secret 中的连接详情验证数据库连接

      kubectl run test-pod --image=postgres --restart=Never \
      --env="PGHOST=$(kubectl get secret timescale-secret -o=jsonpath='{.data.PGHOST}' | base64 --decode)" \
      --env="PGPORT=$(kubectl get secret timescale-secret -o=jsonpath='{.data.PGPORT}' | base64 --decode)" \
      --env="PGDATABASE=$(kubectl get secret timescale-secret -o=jsonpath='{.data.PGDATABASE}' | base64 --decode)" \
      --env="PGUSER=$(kubectl get secret timescale-secret -o=jsonpath='{.data.PGUSER}' | base64 --decode)" \
      --env="PGPASSWORD=$(kubectl get secret timescale-secret -o=jsonpath='{.data.PGPASSWORD}' | base64 --decode)" \
      -- sleep infinity
    2. 在创建的 test-pod 中启动 PostgreSQL 交互式 shell

      kubectl exec -it test-pod -- bash -c "psql -h \$PGHOST -U \$PGUSER -d \$PGDATABASE"

    您将看到 PostgreSQL 交互式终端。

您还可以使用 PostgreSQL Kubernetes operator 来简化安装、配置和生命周期。我们的社区成员推荐以下操作器:

关键词

此页面有任何问题吗?报告问题 或在 GitHub 上编辑此页面