本文将介绍在kubernetes环境中部署一套php应用系统。前端web采用nginx、中间件php以fastcgi的方式运行,后台数据库由mysql主从提供支撑。

各服务组件之间的调用采用dns解析服务名的方式进行,数据和配置文件持久化采用pv和pvc(基于nfs)。

一、通过dockerfile创建php镜像文件

# cat dockerfile

FROM docker.io/openshift/base-centos7:latest

MAINTAINER ylw "ylw@fjhb.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 registry.fjhb.cn/php:0.1 .

# docker push registry.fjhb.cn/php:0.1

5de6c36898b31fcbe940e27b889b3734.png

二、通过yaml文件创建ReplicationController和service

# cat php-rc.yaml

apiVersion: v1

kind: ReplicationController

metadata:

name: php-server

labels:

name: php-server

spec:

replicas: 2

selector:

name: php-server

template:

metadata:

labels:

name: php-server

spec:

containers:

- name: php-server

image: registry.fjhb.cn/php:0.1

volumeMounts:

- mountPath: /usr/share/nginx/html

name: nginx-data

ports:

- containerPort: 9000

volumes:

- name: nginx-data

persistentVolumeClaim:

claimName: nfs-data

# cat php-svc.yaml

apiVersion: v1

kind: Service

metadata:

name: php-server

labels:

name: php-server

spec:

ports:

- port: 9000

protocol: TCP

targetPort: 9000

selector:

name: php-server

# kubectl create -f php-rc.yaml

# kubectl create -f php-svc.yaml

eb40525c82cf1cb11f3b41c806e9da68.png

三、修改nginx配置支持php

# cat /home/nginx/conf.d/test.conf

server {

listen 80;

server_name test.fjhb.cn;

access_log /etc/nginx/test.fjhb.cn.accesslog main;

location / {

root /usr/share/nginx/html;

index index.html index.htm;

}

location ~ \.php$ {

root /usr/share/nginx/html;

fastcgi_pass php-server:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

location ~ /\.ht {

deny all;

}

}

9ded83bf47023817cf563ee8481d6b9e.png

网页访问phpinfo页面测试

9bf07d147daad3434bc409af82d7747f.png

1c5fa8978f4fe40042b44ec4db685ae5.png

498c02d1b89ebb7d4382269d6518103b.png

四、下载Discuz应用部署,测试php和mysql主从的连通性

下载地址:http://www.discuz.net/thread-3796882-1-1.html

# mkdir /home/bbs

# cd /home/bbs

# unzip Discuz_X3.3_SC_UTF8.zip

# mv upload/* ./

通过访问网页进行部署

a8f453d76eecd1a8572a13772ebc93f4.png

d8816108e7ad5727c08e8a6565f760eb.png

f69963be5657daae5f12df0ba41899d8.png

debeb098a24cc1b9554b166949aa83c9.png

5a0aebb7f7f3d6551a73b6e6a5dc09db.png

8f19184e6a8559eb0ea1f7d2386afe6c.png

95f8895f4173c4839f0bad61f67ca098.png

42b40c6f72abd2e8b5968b4a7883ddcb.png

455ca5327feeb6c13e4199a38c00ae99.png

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐