apiVersion: apps/v1
kind: Deployment
metadata:
    name: webserver-php-fpm
    labels:
        app: webserver-php-fpm
spec:
    replicas: 1
    strategy:
        rollingUpdate:
            maxSurge: 1
            maxUnavailable: 0
        type: RollingUpdate
    selector:
        matchLabels:
            app: webserver-php-fpm
    template:
        metadata:
            labels:
                app: webserver-php-fpm
        spec:
            hostAliases:
            -   ip: "127.0.0.1"
                hostnames:
                -   "webserver-php-fpm"
                -   "php-fpm"
                -   "webserver"
            volumes:
                -   name: source-codes
                    emptyDir: {}
                -   name: nginx-configuration
                    configMap:
                        name: nginx-configuration
                        items:
                        -   key: nginx.conf
                            path: default.conf
            initContainers:
                -   name: copy-source-codes-to-volume
                    image: $PHP_FPM_IMAGE
                    command: ["sh", "-c", "cp -r /var/www/html/. /tmp/source-codes"]
                    volumeMounts:
                    -       name: source-codes
                            mountPath: /tmp/source-codes
            containers:
            -   image: $PHP_FPM_IMAGE
                name: php-fpm
                securityContext:
                        runAsUser: 82
                workingDir: /var/www/html
                volumeMounts:
                    -   name: source-codes
                        mountPath: /var/www/html
            -   image: nginx:1.13.10-alpine
                name: webserver
                ports:
                    -   containerPort: 8080
                        name: http
                volumeMounts:
                    -   name: nginx-configuration
                        mountPath: /etc/nginx/conf.d
                    -   name: source-codes
                        mountPath: /var/www/html
                lifecycle:
                    preStop:
                        exec:
                            command:
                            -   nginx -s quit
