Home > OS >  How to import an external file on k8 Manifest
How to import an external file on k8 Manifest

Time:10-06

I have a docker-compose.yml file that has my configuration on importing an external file that installs a postgis configuration when creating a docker image for Postgres,

This is the docker file

services:
  postgres:
    container_name: postgres_db
    build:
      context: .
      dockerfile: Dockerfile-db
    image: postgres
    environment:
      POSTGRES_USER: admin
      POSTGRES_PASSWORD: password
      PGDATA: /data/postgres
    volumes:
      - postgres:/data/postgres
    ports:
      - "5454:5454"
    networks:
      - postgres

the file am importing is called Dockerfile-db .

FROM postgres:14.1


RUN apt-get update && apt-get  install -y postgresql-14-postgis-3  


CMD ["/usr/local/bin/docker-entrypoint.sh","postgres"]

How can I do the same import on a K8 manifest file. this is where I add the database

spec:
  serviceName: zone-service-db-service
  selector:
    matchLabels:
      app: zone-service-db
  replicas: 1
  template:
    metadata:
      labels:
        app: zone-service-db
    spec:
      tolerations:
        - key: "podType"
          operator: "Equal"
          value: "isDB"
          effect: "NoSchedule"
      containers:
        - name: postgres
          image: postgres:latest
          imagePullPolicy: "IfNotPresent"
          ports:
            - containerPort: 5432
          envFrom:
            - configMapRef:
                name: zone-service-db
          volumeMounts:
            - mountPath: /var/lib/postgresql/data
              name: postgredb
          resources:
            requests:
              memory: '256Mi'
              cpu: '100m'
            limits:
              memory: '256Mi'
      volumes:
        - name: postgredb
          persistentVolumeClaim:
            claimName: zone-service-pv-claim

How can I import the Dockerfile-db on the k8 manifest file and be called during the creating of the Postgres container and have the extensions available on the docker-image? Any help is appreciated

CodePudding user response:

I believe you are getting this error

ERROR:  type "geometry" does not exist

The file you have added above will mostly work with docker-compose but for Kubernetes, to have both Postgress and Postgis work together you will have to us the postgis image instead of the postgres image like this

spec:
  serviceName: zone-service-db-service
  selector:
    matchLabels:
      app: zone-service-db
  replicas: 1
  template:
    metadata:
      labels:
        app: zone-service-db
    spec:
      tolerations:
        - key: "podType"
          operator: "Equal"
          value: "isDB"
          effect: "NoSchedule"
      containers:
        - name: postgres
          image: postgis/postgis:latest
          imagePullPolicy: "IfNotPresent"
          ports:
            - containerPort: 5432
          envFrom:
            - configMapRef:
                name: zone-service-db
          volumeMounts:
            - mountPath: /var/lib/postgresql/data
              name: postgredb
          resources:
            requests:
              memory: '256Mi'
              cpu: '100m'
            limits:
              memory: '256Mi'
      volumes:
        - name: postgredb
          persistentVolumeClaim:
            claimName: zone-service-pv-claim

Try this and advise. No need to import external files.

  • Related