Skip to content

Document Docker on k8s specifics #100

Open
@renatomefi

Description

@renatomefi

Context

There are too many things to consider when deploying a PHP Docker setup in Kubernetes, many of them related to good practices and others due to how PHP is designed, the intent of this issue is to list all of them and match whether we have both solved the issue and documented it.

THE list

  • Starting with Docker best practices
    • Package a single app per container
    • Properly handle PID 1, signal handling, and zombie processes
      • PHP Cli doesn't come with pcntl by default.
        Which means SIGTERM and SIGINT will be ignored and the process will die non gracefully, also the application must know how to deal with the signal
      • PHP-FPM doesn't adhere to the standard posix signals IPC, where it'll terminate immediately upon SIGTERM and SIGINT
    • Optimize for the Docker build cache - Done in the official image
    • Remove unnecessary tools - I.e.:
      # those deletions happen since the helper scripts nor the official image are removing them
      && docker-php-source-tarball clean && rm /usr/local/bin/phpdbg && rm -rf /tmp/pear ~/.pearrc \
    • Build the smallest image possible - Same as above
    • Use vulnerability scanning in Container Registry
      • How to patch those images?
      • Patch older versions of the image
    • Properly tag your images
    • Carefully consider whether to use a public image
  • Nginx and PHP-FPM, after handling signals correctly, let's understand the relationship of those components.
    • Does the Nginx process finishes before the PHP-FPM one? I.e: A k8s preStop which checks if the Nginx is dead before PHP-FPM:
 # Considering you have a mount between the nginx and php-fpm containers on `/var/run`
          lifecycle:
            preStop:
              exec:
                command: ["/bin/sh","-c","while test -e /var/run/nginx.pid; do sleep 1; done"]

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationThis issue or pull request is related to documentation and written guidelines

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions