-5

I have a custom docker-compose.yml file below. I created for my postgres cluster.


services:
  pg-master:
    build: '.'
    restart: 'always'
    environment:
      POSTGRES_USER: 'postgres'
      POSTGRES_PASSWORD: 'postgres'
      PGDATA: '/var/lib/postgresql/data/pgdata'
    volumes:
     - ./postgres-data:/var/lib/postgresql/data
    ports:
     - '5432:5432'

  pg-slave:
    build: '.'
    restart: 'always'
    environment:
      POSTGRES_USER: 'postgres'
      POSTGRES_PASSWORD: 'postgres'
      PGDATA: '/var/lib/postgresql/data/pgdata'
      REPLICATE_FROM: 'pg-master'
    volumes:
     - ./postgres-data:/var/lib/postgresql/data
    ports:
     - '5432:5432'
    links:
     - 'pg-master'

It works fine whenever I do docker-compose up. I can see and test that my database got replicated.

However, I don't know how to compose a deployment yml equivalent to that. My goal is to make sure the output will be the same.

I'm using microk8s in my raspberry pi 4 and 3.

Jayson Gonzaga
  • 140
  • 1
  • 4
  • 11

1 Answers1

0

You could think about using Kompose. Its well described in Kubernetes Documentation. You can find there information how install kompose or how to use:

Kompose supports conversion of V1, V2, and V3 Docker Compose files into Kubernetes and OpenShift objects.

Kompose supports a straightforward way to deploy your "composed" application to Kubernetes or OpenShift via kompose up.

Once you have deployed "composed" application to Kubernetes, $ kompose down will help you to take the application out by deleting its deployments and services. If you need to remove other resources, use the 'kubectl' command.

If you would only want to convert to Kubernetes yaml you can use kompose convert.

However, you would need to change it a bit to fit parsing part.

I have tried it on your yaml and with some small edits kompose created Kubernetes YAMLs.

version: "2"

services:

  pg-master:
    image: postgres
    build: '.'
    restart: 'always'
    environment:
      POSTGRES_USER: 'postgres'
      POSTGRES_PASSWORD: 'postgres'
      PGDATA: '/var/lib/postgresql/data/pgdata'
    volumes:
     - ./postgres-data:/var/lib/postgresql/data
    ports:
     - "5432:5432"

  pg-slave:
    build: '.'
    restart: 'always'
    environment:
      POSTGRES_USER: 'postgres'
      POSTGRES_PASSWORD: 'postgres'
      PGDATA: '/var/lib/postgresql/data/pgdata'
      REPLICATE_FROM: 'pg-master'
    volumes:
     - ./postgres-data:/var/lib/postgresql/data
    ports:
     - "5432:5432"
    links:
     - 'pg-master'

OUTPUT:

$ kompose --file docker-compose.yml convert
WARN Volume mount on the host "./postgres-data" isn't supported - ignoring path on the host
WARN Volume mount on the host "./postgres-data" isn't supported - ignoring path on the host
INFO Kubernetes file "pg-master-service.yaml" created
INFO Kubernetes file "pg-slave-service.yaml" created
INFO Kubernetes file "pg-master-deployment.yaml" created
PjoterS
  • 12,841
  • 1
  • 22
  • 54