PHP Local development - minikube or docker-compose?

6/10/2018

I am developing a PHP application - meaning for development I just use a base php container without copying any application code.

My docker-compose setup looks like this:

version: "3.3"
services:
    db:
        image: postgres:10.0
        container_name: app-db
        ports:
            - 65432:5432
        environment:
            POSTGRES_USER: postgres
            POSTGRES_PASSWORD: secret

    web:
        image: falnyr/php-images:7.2-apache-postgres
        container_name: app-webserver
        volumes:
            - .:/var/www/html
        ports:
            - 8081:80

So ports are forwarded to localhost and volumes are mounted. The docker-compose.yml file would be committed to the repository so anyone cloning the code would be able to run docker-compose up to get it running.

Switching to Kubernetes I'd like to keep the same behavior for development only, so generally having a Deployment with following spec:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: backend
spec:
  selector:
    matchLabels:
      app: php-app
      tier: backend
  replicas: 1
  template:
    metadata:
      labels:
        app: php-app
        tier: backend
    spec:
      volumes:
      - name: src
        hostPath:
          path: /home/falnyr/projects/php-app
      containers:
      - name: php-app
        image: falnyr/php-images:7.2-apache-postgres
        volumeMounts:
        - mountPath: /var/www/html
          name: src
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
        ports:
        - containerPort: 80

I am well aware of the fact that hostPath (under volume) doesn't support relative path since the Pod has no idea about the current working directory.

All I need to do is provide a way to all of the devs to just pull the code, run a command and make it running. I can imagine this could be handled via makefile but I'd really like to avoid that if there is an easier way.

Question is what is the best-practice approach to the local development of PHP apps? Should we stick to docker-compose or use Kubernetes with minikube instead?

-- Jan Richter
kubernetes
minikube

2 Answers

6/10/2018

Does it really matter the fact that it is PHP? Would it be any different if it would be python, for example?

If not, then you should consider helm. It is a package manager for kubernetes. You just do helm install package and it installs all the dependencies for your complete app to work.

With helm, I think, you can build your own custom charts.

-- suren
Source: StackOverflow

6/11/2018

As described in the documentation, you can use postStart script to set up your dependencies:

spec:
  containers:
  - name: lifecycle-demo-container
    image: nginx
    lifecycle:
      postStart:
        exec:
          command: ["/bin/sh", "-c", "echo Hello from the postStart handler > /usr/share/message"]

In section command, you can execute any kind of scripts in your container.

-- Nick Rak
Source: StackOverflow