Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document Docker on k8s specifics #100

Open
32 tasks
renatomefi opened this issue Apr 17, 2019 · 2 comments
Open
32 tasks

Document Docker on k8s specifics #100

renatomefi opened this issue Apr 17, 2019 · 2 comments
Labels
Documentation This issue or pull request is related to documentation and written guidelines

Comments

@renatomefi
Copy link
Contributor

renatomefi commented Apr 17, 2019

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"]
@renatomefi renatomefi added the Documentation This issue or pull request is related to documentation and written guidelines label Apr 17, 2019
@stevenjm
Copy link
Contributor

stevenjm commented Apr 17, 2019

Regarding the communication between containers, perhaps also note that Unix socket communication does not need to be bound to the filesystem on Linux (search for "abstract" in http://man7.org/linux/man-pages/man7/unix.7.html). This will even work between containers in the same pod, because the abstract socket namespace is part of the network namespace. Sharing a volume between containers with a socket file is actually unnecessary for this case.

I'm not certain whether both nginx and PHP support using abstract socket names, however.

Also, contrasting "socket" with TCP here is misleading, as TCP sockets are also sockets. The appropriate terminology is "Unix domain socket", or just "Unix socket" for short.

@azjezz
Copy link

azjezz commented Apr 23, 2019

/cc @tomoki1337

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation This issue or pull request is related to documentation and written guidelines
Projects
None yet
Development

No branches or pull requests

3 participants