简体   繁体   English

我们可以在 kubernetes 的同一持久卷中创建多个数据库吗?

[英]Can we create Multiple databases in Same Persistent Volume in kubernetes ?

  • I have Azure Machine (kubernetes) who have Agent of 2 core, 1 GB.我有拥有 2 核 1 GB 代理的 Azure 机器(kubernetes)。 My two services are running on this Machine each have its own Postgres (Deplyment, Service, Pv, PVC).我的两个服务在这台机器上运行,每个服务都有自己的 Postgres(Deplyment、Service、Pv、PVC)。
  • I want to host my third service too on same machine.我也想在同一台机器上托管我的第三个服务。
  • So when I tried to create Postgres Deployment (this too have its own service, PV, PVC) but Pod was stuck in status=ContainerCreating .因此,当我尝试创建 Postgres 部署(这也有自己的服务、PV、PVC)但 Pod 卡在status=ContainerCreating
  • After some digging I got to know that my VM only Supports data-disks .经过一番挖掘,我知道我的VM只支持data-disks

So i thought why not use PVC of earlier deployment in current service like:所以我想为什么不在当前服务中使用早期部署的PVC ,例如:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: third-postgres
  labels:
    name: third-postgres
spec:
  replicas: 1
  template:
    metadata:
      labels:
         name: third-postgres
    spec:
      containers:
      - name: third-postgres
        image: postgres
        env:
          - name: PGDATA
            value: /var/lib/postgresql/data/pgdata
          - name: POSTGRES_USER
            value: third-user
          - name: POSTGRES_PASSWORD
            value: <password>
          - name: POSTGRES_DB
            value: third_service_db
        ports:
          - containerPort: 5432
        volumeMounts:
        - name: third-postgresdata
      mountPath: /var/lib/postgresql/data
  volumes:
  - name: third-postgresdata
    persistentVolumeClaim:
      claimName: <second-postgres-data>
  • Now this Deployment was successfully running but it doesn't create new database third_service_db现在这个部署已经成功运行,但它没有创建新的数据库third_service_db
  • May be because second PVC was already exists so it skips the Db create part ?可能是因为第二个PVC已经存在所以它跳过了 Db 创建部分?
  • So is their any way I can use same PVC for my all services and same PVC can have multiple databases.那么他们的任何方式我都可以为我的所有服务使用相同的PVC ,并且相同的PVC可以有多个数据库。 So that when I run kubectl create -f <path-to-thirst-postgres.yaml> it takes name Database configuration from env Variables and create DB in same PVC因此,当我运行kubectl create -f <path-to-thirst-postgres.yaml>它从环境变量中获取名称数据库配置并在同一个PVC创建数据库

You have to create one PVC per Deployment. 您必须为每个部署创建一个PVC。 Once a PVC has been claimed , it must be released before it can be used again. 一旦PVC一直声称 ,它必须被释放后才能再次使用。

In the case of AzureDisk, the auto-created volumes can only be mounted by a single node ( ReadWriteOnce access mode) so there's one more constraint: each of your Deployments can have at most 1 replica. 对于AzureDisk,自动创建的卷只能由单个节点( ReadWriteOnce访问模式)安装,因此还有一个约束:每个部署最多只能有1个副本。

Yes you can create as much databas as you want on the same Persistent Volume.是的,您可以在同一个 Persistent Volume 上创建任意数量的数据库。 You have to change the path value to store different database.您必须更改path值以存储不同的数据库。 See the example below.请参阅下面的示例。

apiVersion: v1
kind: PersistentVolume
metadata:
  name: ...
  namespace: ...
  labels:
    type: ...
spec:
  storageClassName: ...
  capacity:
    storage: ...
  accessModes:
    - ...
  hostPath:
    path: "/mnt/data/DIFFERENT_PATH_FOR_EACH_DATABASE"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PgAdmin 的 Kubernetes 持久卷挂载 - Kubernetes persistent volume mount for PgAdmin Kubernetes集群中Postgres数据库的持久卷 - Persistent Volume for Postgres Database in Kubernetes Cluster Kubernetes 中 postgres 中持久卷的权限问题 - Permission issue with Persistent volume in postgres in Kubernetes 使用Kubernetes在Postgres中使用多个数据库? - Multiple databases in postgres with Kubernetes? 我们可以在同一个模式中有两个 Postgres 数据库吗? - Can we have two Postgres databases in same schema? 将 Kubernetes Postgres pod 连接到存储在持久卷上的现有数据库 - Connect Kubernetes Postgres pod to existing database stored on persistent volume Kube.netes 从 GCE 持久磁盘卷配置 PVC 显示错误 - Kubernetes provisioning PVC from GCE Persistent disk volume shows error 我们可以在 TypeORM 中为来自不同数据库的表创建一个联合表吗? - Can we create a joint table in TypeORM for tables from different databases? 如何在 docker 中为我的 postgresql 数据库创建持久卷? - How do I create a persistent volume in docker for my postgresql database? 如何为 Bitnami Postgres Helm 部署设置 Kube.netes CIFS 持久卷 PV 权限? - How do I setup Kubernetes CIFS Persistent Volume PV Permissions for Bitnami Postgres Helm Deployment?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM