phpkubernetesfpmcaddycaddyfile

How to run Caddy and PHP-FPM in seprate containers within a POD


I have a Kubernetes deployment that has two container in it.

  1. Caddy webserver
  2. PHP-FPM container

Here is the Caddy config:

    my.caddy.website:80 {
    root * /app
    php_fastcgi localhost:9000
    file_server
    encode gzip
    log {
    output file /var/log/caddy/my.caddy.website.access.log
    }
    @static {
    file
    path *.ico *.css *.js *.gif *.jpg *.jpeg *.png *.svg *.woff *.pdf *.webp
    }
     header @static Cache-Control max-age=5184000
    }

What I was assuming was php code will reside in the PHP-FPM container at /app directory and Caddy server will server the application by forwarding the request to PHP-FPM container.

What is happening is that Caddy is looking for /app directory in its own container and if it finds it it servers it otherwise fails.

How can I achieve this abstraction where on the Caddy container only Caddy config exists and all the code exists on the PHP-FPM container?


Solution

  • You will have to mount the same volume in both the containers. Or better use an NFS mount and mount it to all the containers.