PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, October 18, 2022

[FIXED] How to mount configuration files into a Kubernetes Pod?

 October 18, 2022     docker, kubernetes, persistent-volumes, postgresql     No comments   

Issue

I have a postgres instance that I generally spin up using a docker-compose.yml file. It mounts some configuration files like this:

    volumes:
      - postgres-volume:/var/lib/postgresql/data
      - ./postgresql.conf:/etc/postgresql.conf
      - ./logs:/logs
      - ./pg_hba.conf:/etc/pg_hba.conf

These files are located in the same folder as the docker-compose.yml file is.

My question is: how do I make a Pod that contains this container also mount these configuration files? I read something about PVC in Kubernetes but I'm having a hard time connecting the dots and going from the docker-compose way of thinking to the Kubernetes way of thinking.

Any help is greatly appreciated.


Solution

Easiest approach would be to store the files in a ConfigMap and mount those as volumes in the container.

apiVersion: v1
kind: ConfigMap
metadata:
  name: my-config
data:
  my.properties: |
    url=example.com
    username=username
    password=password
  index.html: |
    Hello world
[...]
  containers:
    - name: my-container
      image: some-registry/some-image
      volumeMounts:
      - name: config-volume
        mountPath: /etc/config/my.properties
        subPath: my.properties
      - name: config-volume
        mountPath: /some/different/path/index.html
        subPath: index.html
  volumes:
    - name: config-volume
      configMap:
        name: my-config
[...]

By that the my.properties file is mounted into /etc/config and index.html into /some/different/path of the my-container file system.

You can also generate the configmap from the file by kubectl create configmap my-config --from-file /path/to/my.properties --from-file /path/to/index.html

See docs for more info on that.



Answered By - Chris
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing