Skip to content

Instantly share code, notes, and snippets.

@wildwind123
Created October 1, 2022 07:52
Show Gist options
  • Save wildwind123/0d186c9f8fdd8a96d22878c14d6e66f0 to your computer and use it in GitHub Desktop.
Save wildwind123/0d186c9f8fdd8a96d22878c14d6e66f0 to your computer and use it in GitHub Desktop.
php-fpm nginx kubernetes example
# example of kubernetes config file php+nginx
# some volume types
# if use minikube should run command
# minikube mount /home/ganbatte/Desktop/project:/home/host2
# create file index.php on shared path /home/ganbatte/Desktop/project/minikubeshared
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-conf
data:
nginx.conf: |
user nginx;
worker_processes 1;
events {
}
http {
server {
listen 80 default_server;
listen [::]:80 default_server;
# Set nginx to serve files from the shared volume!
root /minikubeshared;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
}
}
}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.16
ports:
- containerPort: 80
volumeMounts:
- mountPath: /cache
name: cache-volume
- mountPath: /minikubeshared
name: test-volume
- name: nginx-conf
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
readOnly: true
- image: php:7.1-fpm
name: app
volumeMounts:
- mountPath: /minikubeshared
name: test-volume
ports:
- containerPort: 9000
volumes:
- name: cache-volume
emptyDir: {}
- name: test-volume
hostPath:
path: /home/host2/minikubeshared
type: Directory
- name: nginx-conf
configMap:
name: nginx-conf
items:
- key: nginx.conf
path: nginx.conf
---
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
selector:
app: nginx
type: LoadBalancer
ports:
- protocol: TCP
port: 80
targetPort: 80
nodePort: 30000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment