k8s 部署nginx + php + mysql
dockerfile
[root@centos-7 php]# more dockerfile
FROM docker.io/openshift/base-centos7:latest
MAINTAINER lintianlai "lintianlai@ylwl.cn"
RUN yum makecache
RUN yum -y install php-fpm php php-gd php-mysql php-mbstring php-xml php-mcrypt php-imap php-odbc php-pear php-xmlrpc
RUN sed -i 's/listen = 127.0.0.1:9000/listen = 0.0.0.0:9000/' /etc/php-fpm.d/www.conf
RUN sed -i 's/listen.allowed_clients = 127.0.0.1/;listen.allowed_clients = 127.0.0.1/' /etc/php-fpm.d/www.conf
EXPOSE 9000
CMD ["/sbin/php-fpm"]
docker build -t php:0.1 .
php-deployment.yaml
[root@centos-7 php]# more php-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: php-server
labels:
name: php-server
namespace: ns-nginx
spec:
replicas: 1
selector:
matchLabels:
app: php-server
template:
metadata:
labels:
app: php-server
spec:
containers:
- name: php-server
image: php:0.1
volumeMounts:
- mountPath: /var/www/html/
name: nginx-data
ports:
- containerPort: 9000
volumes:
- name: nginx-data
hostPath:
path: /root/k8s/nmp/html
kubctl apply -f php-deployment.yaml
php-svc.yaml
[root@centos-7 php]# more php-svc.yaml
apiVersion: v1
kind: Service
metadata:
name: php
namespace: ns-nginx
spec:
ports:
- name: php
port: 9000
protocol: TCP
targetPort: 9000
selector:
app: php-server
kubectl apply -f php-svc.yaml
nginx-deploy.yaml
[root@centos-7 php]# more nginx-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-php
namespace: ns-nginx
spec:
selector:
matchLabels:
app: nginx-php
replicas: 1
template:
metadata:
labels:
app: nginx-php
spec:
containers:
- name: nginx-php
image: nginx:alpine
ports:
- containerPort: 80
volumeMounts:
- name: nginx-data
mountPath: /usr/share/nginx/html
- name: nginx-conf
mountPath: /etc/nginx/conf.d/
volumes:
- name: nginx-data
hostPath:
path: /root/k8s/nmp/html
- name: nginx-conf
hostPath:
path: /root/k8s/nmp/conf
kubectl apply -f nginx-deploy.yaml
nginx-svc.yaml
[root@centos-7 php]# more nginx-svc.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-php
namespace: ns-nginx
spec:
type: NodePort
ports:
- name: nginx
port: 80
protocol: TCP
targetPort: 80
nodePort: 30003
selector:
app: nginx-php
kubectl apply -f nginx-svc.yaml
浏览器访问http://192.168.21.63:30003/info.php