k8s 部署 nginx+php-fpm
https://www.cnblogs.com/wuxinchun/p/15697919.html
https://blog.51cto.com/u_15620612/9551113
https://www.cnblogs.com/douyi/p/12099701.html
https://blog.csdn.net/PlatoWG/article/details/124092480
https://www.dismall.com/thread-14660-1-1.html
https://www.dismall.com/thread-15912-1-1.html
https://www.jb51.net/server/3032907dw.htm
https://zhuanlan.zhihu.com/p/649470458
给docker下的php容器安装gd
https://blog.csdn.net/apple9005/article/details/130225198
https://blog.csdn.net/longfeng995/article/details/131473101
docker php安装redis扩展
https://blog.csdn.net/longfeng995/article/details/130557612
https://blog.csdn.net/qq_38421226/article/details/128017953
制作镜像
1
2拉取php基础进行
3[zhangcong@master ~]$ docker pull php:7.4-fpm
4
5
6
7查看php镜像
8[zhangcong@master ~]$ docker images
9REPOSITORY TAG IMAGE ID CREATED SIZE
10php 7.4-fpm c35e6c37cf2c 5 days ago 494MB
11
12
13
14运行容器
15[zhangcong@master ~]$ docker run c35e6c37cf2c
16[22-Feb-2024 13:23:24] NOTICE: fpm is running, pid 1
17[22-Feb-2024 13:23:24] NOTICE: ready to handle connections
18
19
20
21查看正则运行的php容器
22[zhangcong@master ~]$ docker ps
23CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
24f1f0e6b3db4d c35e6c37cf2c "docker-php-entrypoi…" 14 seconds ago Up 12 seconds 9000/tcp mystifying_rosalind
25
26
27
28进入容器内部,根据需要,安装插件
29[zhangcong@master ~]$ docker exec -it f1f0e6b3db4d /bin/sh
30
31设置国内软件源
32# mv /etc/apt/sources.list /etc/apt/sources.list.bak
33
34# cat > /etc/apt/sources.list <<EOF
35deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
36# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
37deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
38# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
39deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
40# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
41deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
42# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
43EOF
44
45# apt-get update
46
47安装gd扩展(图形库,验证码的图片需要用到)
48# apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libmcrypt-dev libpng-dev
49# docker-php-ext-configure gd --enable-gd --with-freetype --with-jpeg
50# docker-php-ext-install gd
51
52
53
54安装mysql扩展
55# docker-php-ext-install pdo_mysql
56# docker-php-ext-install mysqli
57
58安装redis扩展(下载地址:https://pecl.php.net/package/redis)
59# curl https://pecl.php.net/get/redis-5.3.7.tgz -o /usr/src/redis-5.3.7.tgz
60# mkdir -p /usr/src/php/ext/
61# tar -zxvf /usr/src/redis-5.3.7.tgz -C /usr/src/php/ext/
62# rm -rf /usr/src/php/ext/package.xml
63# mv /usr/src/php/ext/redis-5.3.7 /usr/src/php/ext/redis
64# docker-php-ext-install redis
65
66
67查看已安装的扩展
68php -m
69
70
71扩展文件路径
72# ls /usr/local/lib/php/extensions/no-debug-non-zts-20190902/
73gd.so mysqli.so opcache.so pdo_mysql.so redis.so sodium.so
74
75
76配置文件路径
77# ls /usr/local/etc/php/conf.d
78docker-php-ext-gd.ini docker-php-ext-mysqli.ini docker-php-ext-pdo_mysql.ini docker-php-ext-redis.ini docker-php-ext-sodium.ini
79
80停止容器
81[zhangcong@master ~]$ docker stop f1f0e6b3db4d
82f1f0e6b3db4d
83
84
85
86通过容器构建镜像
87[zhangcong@master php]$ docker commit e17db3eee554 registry.cn-hangzhou.aliyuncs.com/conggege325/pub-repository:php-7.4-fpm-gd-mysql-redis
88
89
90打包镜像到仓库
91[zhangcong@master php]$ docker push registry.cn-hangzhou.aliyuncs.com/conggege325/pub-repository:php-7.4-fpm-gd-mysql-redis
在k8s中部署
1[zhangcong@master k8s]$ cat discuz-deployment-configMap-service.yaml
2kind: Service
3apiVersion: v1
4metadata:
5 name: discuz-service
6 namespace: my
7spec:
8 type: NodePort
9 selector:
10 app: discuz
11 ports:
12 - port: 80
13 targetPort: 80
14 nodePort: 31011
15---
16kind: ConfigMap
17apiVersion: v1
18metadata:
19 name: discuz-nginx-config
20 namespace: my
21data:
22 nginx.conf: |
23 worker_processes auto;
24 events {
25 worker_connections 1024;
26 }
27 http {
28 include mime.types;
29 default_type application/octet-stream;
30 sendfile on;
31 keepalive_timeout 65;
32 server {
33 listen 80;
34 server_name localhost;
35 index index.php index.html index.htm;
36 root /var/www/html;
37 location ~ \.php {
38 include fastcgi_params;
39 fastcgi_param REQUEST_METHOD $request_method;
40 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
41 fastcgi_pass 127.0.0.1:9000;
42 }
43 }
44 }
45---
46kind: Deployment
47apiVersion: apps/v1
48metadata:
49 name: discuz-deployment
50 namespace: my
51spec:
52 selector:
53 matchLabels:
54 app: discuz
55 replicas: 1
56 template:
57 metadata:
58 labels:
59 app: discuz
60 spec:
61 containers:
62 - name: discuz-php-fpm
63 image: registry.cn-hangzhou.aliyuncs.com/conggege325/pub-repository:php-7.4-fpm-gd-mysql-redis
64 imagePullPolicy: IfNotPresent
65 ports:
66 - containerPort: 9000
67 volumeMounts:
68 - name: nginx-www
69 mountPath: /var/www/html
70 - name: discuz-nginx
71 image: nginx:1.25.3
72 imagePullPolicy: IfNotPresent
73 ports:
74 - containerPort: 80
75 volumeMounts: # nginx 容器挂载了两个 volume,一个是与 php-fpm 容器共享的 volume,另外一个是配置了 nginx.conf 的 volume
76 - name: nginx-www
77 mountPath: /var/www/html
78 - name: nginx-config
79 mountPath: /etc/nginx/nginx.conf
80 subPath: nginx.conf
81 volumes:
82 - name: nginx-www
83 hostPath:
84 path: /home/zhangcong/dev/discuz/upload
85 - name: nginx-config
86 configMap:
87 name: discuz-nginx-config
88---
89apiVersion: networking.k8s.io/v1
90kind: Ingress
91metadata:
92 name: discuz-ingress
93 namespace: my
94spec:
95 ingressClassName: nginx
96 tls:
97 - hosts:
98 - discuz.zcily.com
99 secretName: https-secret
100 rules:
101 - host: discuz.zcily.com
102 http:
103 paths:
104 - path: /
105 pathType: Prefix
106 backend:
107 service:
108 name: discuz-service
109 port:
110 number: 80
111
112
113[zhangcong@master k8s]$ kubectl apply -f discuz-deployment-configMap-service.yaml
评论