kubernetes集群中怎么部署php应用,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
一、通过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
二、通过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
三、修改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; } }
网页访问phpinfo页面测试
四、下载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/* ./
通过访问网页进行部署
看完上述内容,你们掌握kubernetes集群中怎么部署php应用的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。