├── .gitignore ├── Dockerfile ├── LICENSE ├── README.md ├── app ├── index.php └── info.php ├── docker ├── build-push.sh ├── nginx │ ├── nginx.conf │ └── sites-enabled │ │ └── myapp ├── php-fpm │ ├── php-fpm.conf │ └── pool.d │ │ └── www.conf ├── reload-local.sh ├── start-local.sh └── stop-local.sh └── kubernetes ├── kube-down.sh ├── kube-up.sh └── php-nginx-app.yml /.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/b00gizm/kubernetes-php-nginx/80c7fce60ad280b19b51145b02bb21c90095d203/.gitignore -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu 2 | 3 | RUN apt-get update && apt-get upgrade -y 4 | RUN apt-get install -y \ 5 | php5-fpm \ 6 | nginx 7 | 8 | ADD ./docker/nginx/nginx.conf /etc/nginx/nginx.conf 9 | RUN rm /etc/nginx/sites-enabled/default 10 | ADD ./docker/nginx/sites-enabled/ /etc/nginx/sites-enabled 11 | 12 | ADD ./docker/php-fpm/php-fpm.conf /etc/php5/fpm/php-fpm.conf 13 | ADD ./docker/php-fpm/pool.d/ /etc/php5/fpm/pool.d 14 | 15 | RUN mkdir -p /etc/php5/cli; ln -s /etc/php5/fpm/php.ini /etc/php5/cli/php.ini 16 | RUN sed -i "s/;date.timezone =/date.timezone = Europe\/Berlin/" /etc/php5/fpm/php.ini 17 | 18 | ADD app/ /app 19 | 20 | EXPOSE 80 9000 21 | 22 | WORKDIR /app 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) [year] [fullname] 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## kubernetes-php-nginx 2 | 3 | Run Nginx + PHP (FPM) on your Kubernetes cluster! 4 | 5 | This is an example project targeting anyone who is dying to find a pragmatic example and/or resources for getting started with [Kubernetes](http://kubernetes.io). 6 | 7 | ### Prerequisites 8 | 9 | This example works best (only?) for a Kubernetes setup on your local machine with Vagrant. Please follow the instructions on the Kubernetes website and return here after everything is set up. 10 | 11 | For convenience, I suggest to also install the Kubernetes CLI aka `kubectl` on your machine. On OS X (with Homebrew), it's as easy as 12 | 13 | ```bash 14 | brew install kubernetes-cli 15 | ``` 16 | 17 | ### Up and Running 18 | 19 | Get up and running within seconds! Just run `kube-up.sh` inside the `kubernetes` folder: 20 | 21 | ```bash 22 | $ kubernetes/kube-up.sh 23 | services/php-fpm-svc 24 | services/php-nginx-svc 25 | replicationcontrollers/php-fpm 26 | replicationcontrollers/php-nginx 27 | --- 28 | When pod(s) are ready, hit http://10.245.1.3:30564 in your browser! 29 | ``` 30 | 31 | Here's what it does in a nutshell: It creates two pods, each running a [Docker](http://docker.io) container based on the [b00gizm/php-nginx](https://hub.docker.com/r/b00gizm/php-nginx/) image (see `Dockerfile` inside this repo for details). One pod is responsible for running the PHP FPM process and the other one for running Nginx. 32 | 33 | It also creates two services, one for PHP FPM and one for Nginx, for load balancing traffic between the different pods. Without any changes, each service is only responsible for one pod, but you can scale this just as you like by changing the value for the `replication` fields inside `kubernetes/php-nginx-app.yml` 34 | 35 | (I will elaborate on the nitty gritty details some time later, so please refer to the official [Kubernetes docs](http://kubernetes.io/v1.0), if you want details right know.) 36 | 37 | Check if your pods are ready (running): 38 | 39 | ```bash 40 | $ kubectl get po 41 | NAME READY STATUS RESTARTS AGE 42 | php-fpm-fyonz 1/1 Running 0 12s 43 | php-nginx-eew3w 1/1 Running 0 12s 44 | ``` 45 | 46 | And then hit the URL dumped by `kube-up.sh` above in your browser (__please note that your actual IP address and port might and will vary!__) and you'll be greeted by a "Hello World" page. 47 | 48 | After you're done, you can bring everything down via `kubernetes/kube-down.sh`. 49 | 50 | ### Running "locally" on Docker 51 | 52 | If you're like me, you'll also like to test this app on your local Docker host: 53 | 54 | ```bash 55 | docker build -t b00gizm/php-nginx . 56 | ... 57 | docker tag b00gizm/php-nginx latest 58 | docker/start-local.sh 59 | 993277dd6a21364139fa29a5ff2bf7eb5d25e07bba577d11b827bda41eb96fcb 60 | 984fa94801be481e86d68c86e86e1268c8da262983186bc0a4a7dfeca3d722e9 61 | ``` 62 | 63 | The app will be available in your browser via `http://:8080` 64 | 65 | When you're done, just execute `docker/stop-local.sh` to stop it. 66 | 67 | ### Maintainer 68 | 69 | Pascal Cremer 70 | 71 | * Email: 72 | * Twitter: [@b00gizm](https://twitter.com/b00gizm) 73 | * Web: [http://codenugget.co](http://codenugget.co) 74 | 75 | ### License 76 | 77 | > The MIT License (MIT) 78 | > 79 | > Copyright (c) 2015 Pascal Cremer 80 | > 81 | >Permission is hereby granted, free of charge, to any person obtaining a copy 82 | >of this software and associated documentation files (the "Software"), to deal 83 | >in the Software without restriction, including without limitation the rights 84 | >to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 85 | >copies of the Software, and to permit persons to whom the Software is 86 | >furnished to do so, subject to the following conditions: 87 | > 88 | >The above copyright notice and this permission notice shall be included in all 89 | >copies or substantial portions of the Software. 90 | > 91 | >THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 92 | >IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 93 | >FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 94 | >AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 95 | >LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 96 | >OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 97 | >SOFTWARE. 98 | -------------------------------------------------------------------------------- /app/index.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Kubernetes Test 5 | 6 | 13 | 14 | 15 |

Hello PHP!

16 |

Today is .

17 | 18 | 19 | -------------------------------------------------------------------------------- /app/info.php: -------------------------------------------------------------------------------- 1 |