├── LICENSE ├── README.md ├── cluster-issuer.yaml ├── fast-cgi-configmap.yaml ├── ingress.yaml ├── nginx-configmap.yaml ├── wordpress-configmap.yaml ├── wordpress-deployment.yaml └── wordpress-service.yaml /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Harsh Manvar 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-wordpress-fpm-nginx 2 | Kubernetes custom wordpress deployment with php-fpm & nginx ingress 3 | 4 | 5 | ## Getting Started 6 | 7 | These instructions will get you a copy of the project up and running on your cloud machine for development and testing purposes. 8 | 9 | 10 | ### Prerequisites 11 | 12 | Kubernetes cluster with nginx ingress installed 13 | 14 | ``` 15 | Kubernetes <= 0.10 16 | 17 | ``` 18 | 19 | ### Installing 20 | 21 | A step by step series of examples that tell you how to get a setup wordpress env running 22 | 23 | 24 | Build custom WordPress docker image using official php-fpm WordPress docker version 25 | 26 | Official WordPress docker : https://hub.docker.com/_/wordpress 27 | 28 | Exmple docker file 29 | 30 | ``` 31 | FROM wordpress:5-php7.2 32 | COPY ./ /usr/src/wordpress/ 33 | EXPOSE 80 34 | EXPOSE 9000 35 | ``` 36 | ### If WordPress taking Db connection values from envrionment variable 37 | 38 | Edit & apply wordpress-configmap.yaml 39 | 40 | ``` 41 | kubectl apply -f wordpress-configmap.yaml 42 | ``` 43 | 44 | ### If want to implment fast-cgi with nginx ingress 45 | 46 | Edit & apply fast-cgi-configmap.yaml & ingress.yaml (uncomment annotations) 47 | 48 | ``` 49 | kubectl apply -f fast-cgi-configmap.yaml 50 | 51 | kubectl apply -f ingress.yaml 52 | ``` 53 | 54 | ### SSL/TLS certificate 55 | 56 | If want to use SSL/TLS cetificate setup cert-manager and apply clusterissuer 57 | 58 | Edit & apply cluster-issuer.yaml 59 | 60 | ``` 61 | kubectl apply -f cluster-issuer.yaml 62 | ``` 63 | 64 | ### WordPress service deployment 65 | 66 | WordPress deployment will create One with Two container inside it (Nginx + Wordpress php-fpm) 67 | 68 | Edit & apply wordpress-deployment.yaml & wordpress-service.yaml 69 | 70 | ``` 71 | kubectl apply -f wordpress-service.yaml 72 | 73 | kubectl apply -f wordpress-deployment.yaml 74 | ``` 75 | 76 | ### Traffic flow 77 | 78 | nginx ingress > nginx container inside POD > wordpress container (over localhost in same POD) -------------------------------------------------------------------------------- /cluster-issuer.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: cert-manager.io/v1alpha2 2 | kind: ClusterIssuer 3 | metadata: 4 | name: wordpress-dev 5 | spec: 6 | acme: 7 | server: https://acme-v02.api.letsencrypt.org/directory 8 | email: example@gmail.com 9 | privateKeySecretRef: 10 | name: wordpress-dev 11 | solvers: 12 | - http01: 13 | ingress: 14 | class: nginx 15 | -------------------------------------------------------------------------------- /fast-cgi-configmap.yaml: -------------------------------------------------------------------------------- 1 | #use this if you want to use fast-cgi with nginx ingress 2 | apiVersion: v1 3 | kind: ConfigMap 4 | metadata: 5 | name: word-cm 6 | data: 7 | SCRIPT_FILENAME: "/var/www/html/index.php" 8 | FASTCGI_PASS : "wordpress-site:9000" 9 | fastcgi_pass: "wordpress-site:9000" 10 | -------------------------------------------------------------------------------- /ingress.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: networking.k8s.io/v1beta1 2 | kind: Ingress 3 | metadata: 4 | annotations: 5 | kubernetes.io/ingress.class: "nginx" 6 | cert-manager.io/cluster-issuer: wordpress-dev 7 | # nginx.ingress.kubernetes.io/proxy-read-timeout: "1800" 8 | # nginx.ingress.kubernetes.io/proxy-send-timeout: "1800" 9 | # nginx.ingress.kubernetes.io/fastcgi_send_timeout: "1800" 10 | # nginx.ingress.kubernetes.io/fastcgi_read_timeout: "1800" 11 | # nginx.ingress.kubernetes.io/backend-protocol: "FCGI" 12 | # nginx.ingress.kubernetes.io/fastcgi-index: "index.php" 13 | # nginx.ingress.kubernetes.io/fastcgi-params-configmap: "development/word-cm" 14 | # nginx.ingress.kubernetes.io/server-snippets: | 15 | # location ~ \.php$ { 16 | # try_files $uri =404; 17 | # fastcgi_split_path_info ^(.+\.php)(/.+)$; 18 | # fastcgi_pass wordpress-site:9000; 19 | # fastcgi_index index.php; 20 | # include fastcgi_params; 21 | # fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 22 | # fastcgi_param PATH_INFO $fastcgi_path_info; 23 | # } 24 | name: wordpress-dev 25 | namespace: development 26 | spec: 27 | rules: 28 | - host: dev.example.io 29 | http: 30 | paths: 31 | - backend: 32 | serviceName: wordpress-site 33 | servicePort: 80 34 | tls: 35 | - hosts: 36 | - dev.example.io 37 | secretName: wordpress-dev 38 | -------------------------------------------------------------------------------- /nginx-configmap.yaml: -------------------------------------------------------------------------------- 1 | #nginx configmap 2 | apiVersion: v1 3 | kind: ConfigMap 4 | metadata: 5 | name: nginxthroughpass 6 | namespace: development 7 | data: 8 | default.conf: |- 9 | server { 10 | listen 80 default_server; 11 | root /var/www/html; 12 | server_name _; 13 | index index.php; 14 | location / { 15 | try_files $uri $uri/ /index.php?$args; 16 | } 17 | 18 | location ~ \.php$ { 19 | fastcgi_split_path_info ^(.+\.php)(/.+)$; 20 | fastcgi_pass 127.0.0.1:9000; 21 | fastcgi_index index.php; 22 | include fastcgi_params; 23 | fastcgi_param PATH_INFO $fastcgi_path_info; 24 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /wordpress-configmap.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | data: 3 | WP_WT_MYSQL_DB: wordpress 4 | WP_WT_MYSQL_HOST: 192.168.1.2 5 | WP_WT_MYSQL_PASSWORD: password 6 | WP_WT_MYSQL_USER: root 7 | kind: ConfigMap 8 | metadata: 9 | name: wordpress-configmap 10 | #use if wordpress taking db via environment variable 11 | -------------------------------------------------------------------------------- /wordpress-deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: extensions/v1 2 | kind: Deployment 3 | metadata: 4 | labels: 5 | app: wordpress-site 6 | name: wordpress-site 7 | namespace: development 8 | spec: 9 | progressDeadlineSeconds: 600 10 | replicas: 1 11 | revisionHistoryLimit: 10 12 | selector: 13 | matchLabels: 14 | app: wordpress-site 15 | tier: frontend 16 | strategy: 17 | rollingUpdate: 18 | maxSurge: 25% 19 | maxUnavailable: 25% 20 | type: RollingUpdate 21 | template: 22 | metadata: 23 | creationTimestamp: null 24 | labels: 25 | app: wordpress-site 26 | tier: frontend 27 | spec: 28 | volumes: 29 | - configMap: 30 | defaultMode: 256 31 | name: nginxthroughpass 32 | optional: false 33 | name: nginxconf 34 | - name: shared-files 35 | emptyDir: {} 36 | containers: 37 | - name: app 38 | image: 39 | imagePullPolicy : IfNotPresent 40 | volumeMounts: 41 | - name: shared-files 42 | mountPath: /var/www/html 43 | envFrom: 44 | - configMapRef: 45 | name: wordpress-configmap 46 | - name: nginx 47 | image: nginx 48 | imagePullPolicy : IfNotPresent 49 | volumeMounts: 50 | - name: shared-files 51 | mountPath: /var/www/html 52 | - mountPath: /etc/nginx/conf.d 53 | name: nginxconf 54 | readOnly: true -------------------------------------------------------------------------------- /wordpress-service.yaml: -------------------------------------------------------------------------------- 1 | piVersion: v1 2 | kind: Service 3 | metadata: 4 | labels: 5 | app: wordpress-site 6 | name: wordpress-site 7 | spec: 8 | ports: 9 | - name: http 10 | port: 80 11 | protocol: TCP 12 | targetPort: 80 13 | - name: https 14 | port: 9000 15 | protocol: TCP 16 | targetPort: 9000 17 | selector: 18 | app: wordpress-site 19 | tier: frontend 20 | sessionAffinity: None 21 | type: ClusterIP 22 | --------------------------------------------------------------------------------