k8s集群PHP环境使用_php 使用ks8
1、下载wordpress2、创建数据库(数据库我使用yum下载的,数据库尽量不要部署在k8s集群中)3、把wordpress代码放入到NAS存储中。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上软件测试知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
1、下载wordpress
wget https://cn.wordpress.org/latest-zh_CN.zip
2、创建数据库(数据库我使用yum下载的,数据库尽量不要部署在k8s集群中)
create database wordpress DEFAULT CHARACTER SET utf8;
grant all on wordpress.\* to 'wordpress'@'%' identified by '123456';
3、把wordpress代码放入到NAS存储中
mkdir /data -p
mount -t nfs -o vers=4,minorversion=0,noresvport 12XXXXXXXxx.cn-hongkong.nas.aliyuncs.com:/ /data
mv wordpress /data/
三、写dockerfile和构建镜像(我这自己写的nginx镜像,挂载配置或者使用secret的方法也能更改配置)
mkdir -p Dockerfile
[root@k8s-m Dockerfile]# cat default.conf
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
root /var/www/html;
fastcgi_pass php-svc.default.svc.cluster.local:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
[root@k8s-m Dockerfile]# cat Dockerfile
FROM nginx:1.15.4-alpine
LABEL maintainer="zhang 1232@qq.com"
COPY default.conf /etc/nginx/conf.d/
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
#构建镜像(没有镜像仓库的话,要把镜像导入到其它服务器上)
[root@k8s-m Dockerfile]# docker build -t mynginx:2.0 ./
#查看镜像
[root@k8s-m Dockerfile]# docker images|grep mynginx
mynginx 2.0 2fd9a272
四、配置nginx和php
1、创建与导入php的svc和deploy
[root@k8s-m ~]# cat php.yaml
apiVersion: v1
kind: Service
metadata:
name: php-svc
spec:
selector:
name: php
ports:
- port: 9000
name: http-php
targetPort: 9000
protocol: TCP
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-php-deploy
spec:
replicas: 3
selector:
matchLabels:
name: php
template:
metadata:
labels:
name: php
spec:
containers:
- name: php
image: php:7.2-fpm
ports:
- name: http-php
containerPort: 9000
volumeMounts:
- name: php-code
mountPath: /var/www/html/
volumes:
- name: php-code
nfs:
path: /wordpress/
server: 12xxxxxxxxx.cn-hongkong.nas.aliyuncs.com
2、创建与导入nginx的svc和deploy
[root@k8s-m ~]# cat nginx-deploy.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-svc
spec:
selector:
name: nginx
ports:
- port: 80
name: http
targetPort: 80
protocol: TCP
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-nginx-deploy
spec:
replicas: 3
selector:
matchLabels:
name: nginx
template:
metadata:
labels:
name: nginx
spec:
containers:
- name: nginx
image: mynginx:2.0
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 80
volumeMounts:
- name: html
mountPath: /usr/share/nginx/html/
volumes:
- name: html
nfs:
path: /wordpress/
server: 124xxxxxxxxxxxxx-hongkong.nas.aliyuncs.com
3、查看
[root@k8s-m ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 4h15m
nginx-svc ClusterIP 10.101.81.167 <none> 80/TCP 99m
php-svc ClusterIP 10.111.89.228 <none> 9000/TCP 99m
[root@k8s-m ~]# kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
my-nginx-deploy 3/3 3 3 99m
my-php-deploy 3/3 3 3 100m
4、创建Ingress访问
[root@k8s-m ~]# cat wordpress-ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-nginx
spec:
rules:
- host: haha.zhang.com
http:
paths:
- backend:
serviceName: nginx-svc
servicePort: 80
[root@k8s-m ~]# kubectl apply -f wordpress-ingress.yaml
ingress.extensions/ingress-nginx created
5、访问测试
五、PHP扩展安装
php容器中的ini扩展文件路径:/usr/local/etc/php/conf.d/
1、进入php容器中
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
.(img-JwLQ5fSZ-1715804432999)]
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
更多推荐
所有评论(0)