部署wordpress、部署discuz、构建nginx、PHP镜像

一、部署wordpress

1、构建镜像
2、构思架构,同时编写配置清单

  • 1、创建名称空间
  • 2、部署
  • 3、测试网络连接

3、部署

创建mysql的命名空间
[root@k8s-master-01 wordpress]# cat mysql.yaml 
apiVersion: v1
kind: Namespace
metadata:
  name: mysql
---
创建数据库控制器
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
spec:
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
        - name: mysql
          image: mysql:5.7
          env:
            - name: MYSQL_ROOT_PASSWORD
              value: "123456"
            - name: MYSQL_DATABASE
              value: wordpress
---
创建数据库service
apiVersion: v1
kind: Service
metadata:
  name: mysql
spec:
  selector:
    app: mysql
  ports:
    - port: 3306
      targetPort: 3306
  type: NodePort

创建项目的名称空间
[root@k8s-master-01 wordpress]# cat wordpress.yaml 
apiVersion: v1
kind: Namespace
metadata:
  namespace: wordpress
  name: wordpress
---
创建项目的控制器
apiVersion: apps/v1
kind: Deployment
metadata:
  name: wordpress
  namespace: wordpress
spec:
  selector:
    matchLabels:
      app: wordpress
  template:
    metadata:
      labels:
        app: wordpress
    spec:
      containers:
        - name: php
          image: alvinos/php:wordpress-v2
        - name: nginx
          image: alvinos/nginx:wordpress-v2

---
创建项目的service
apiVersion: v1
kind: Service
metadata:
  name: wordpress
  namespace: wordpress
spec:
  selector:
    app: wordpress
  ports:
    - port: 80
      targetPort: 80
      name: http
      nodePort: 30080
    - port: 443
      targetPort: 443
      name: https
  type: NodePort

访问:
在这里插入图片描述

二、健康检查搭建discuz

1、创建目录

[root@k8s-m-01 ~]# mkdir -p discuz
[root@k8s-m-01 ~]# cd discuz/
[root@k8s-m-01 discuz]# mkdir php 
[root@k8s-m-01 discuz]# mkdir nginx

2、构建nginx

# 1、上次代码包
[root@k8s-m-01 nginx]# wget http://www.mmin.xyz:81/package/blog/Discuz_X3.4_SC_UTF8_20210320_%281%29.zip
# 2、解压后把upload改名成discuz
[root@k8s-m-01 nginx]# mv upload discuz
# 3、准备nginx文件
[root@k8s-m-01 nginx]# vim nginx.conf 
user  www;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    gzip  on;
    gzip_min_length 1k;
    gzip_comp_level 1;
    gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png application/vnd.ms-fontobject font/ttf font/opentype font/x-woff image/svg+xml;
    gzip_vary on;
    gzip_disable "MSIE [1-6]\.";
    gzip_buffers 32 4k;
    gzip_http_version 1.0;

    include /etc/nginx/conf.d/*.conf;
}
[root@k8s-m-01 nginx]# vim default.conf 
server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;
    root   /usr/share/nginx/html;
    
    location / {
        index  index.php;
    }

    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

}
# 4、构建Dockerfile
[root@k8s-m-01 nginx]# vim Dockerfile 
FROM nginx 

RUN groupadd www -g 666 && \
    useradd www -u 666 -g 666

ADD nginx.conf /etc/nginx/nginx.conf

ADD default.conf /etc/nginx/conf.d/default.conf

RUN rm -rf  /usr/share/nginx/html

ADD discuz /usr/share/nginx/html

RUN chown -R www.www /usr/share/nginx/html

WORKDIR /usr/share/nginx/html

EXPOSE 80  443

CMD ["nginx","-g","daemon off;"]
# 5、查看
[root@k8s-m-01 nginx]# ll
total 20
-rw-r--r--  1 root root  389 Aug  9 09:05 default.conf
drwxr-xr-x 13 root root 4096 Aug  9 10:19 discuz
-rw-r--r--  1 root root  353 Aug  9 09:13 Dockerfile
-rw-r--r--  1 root root 1043 Aug  9 09:05 nginx.conf
# 6、上次到自己仓库(也可以不需要)
[root@k8s-m-01 nginx]# docker build -t  registry.cn-shanghai.aliyuncs.com/aliyun_mm/discuz:nginx-v2 .
[root@k8s-m-01 nginx]# docker push  registry.cn-shanghai.aliyuncs.com/aliyun_mm/discuz:nginx-v2

3、构建php

# 1、把discuz包也复制到php中
[rook8s-m-01 php]# cp -r ../nginx/discuz .
# 2、上传php.tar.gz
[rook8s-m-01 php]# wget http://www.mmin.xyz:81/package/lnmp/php.tar.gz
# 3、编写Dockerfile
[root@k8s-m-01 php]# vim Dockerfile 
FROM centos:7

RUN groupadd www -g 666 && \
    useradd www -u 666 -g 666

ADD php.tar.gz /tmp

RUN yum -y localinstall /tmp/*.rpm

RUN sed -i 's#apache#www#g' /etc/php-fpm.d/www.conf
RUN sed -i 's#127.0.0.1:9000#9000#g' /etc/php-fpm.d/www.conf
RUN sed -i 's#;request_terminate_timeout#request_terminate_timeout#g' /etc/php-fpm.d/www.conf

EXPOSE 9000

WORKDIR /usr/share/nginx/html

ADD discuz /usr/share/nginx/html

RUN chown -R www.www /usr/share/nginx/html

CMD php-fpm -F
# 4、查看
[root@k8s-m-01 php]# ll
total 19436
drwxr-xr-x 13 root root     4096 Aug  9 10:19 discuz
-rw-r--r--  1 root root      477 Aug  9 09:24 Dockerfile
-rw-r--r--  1 root root 19889622 Jul 25 01:01 php.tar.gz
# 5、上次到自己仓库(也可以不需要)
[root@k8s-m-01 nginx]# docker build -t  registry.cn-shanghai.aliyuncs.com/aliyun_mm/discuz:php-v2 .
[root@k8s-m-01 nginx]# docker push  registry.cn-shanghai.aliyuncs.com/aliyun_mm/discuz:php-v2

3、编写yaml文件

# 1、编写mysql.yaml
[root@k8s-m-01 discuz]# vim mysql.yaml 
kind: Namespace
apiVersion: v1
metadata:
  name: mysql
---
kind: Deployment
apiVersion: apps/v1
metadata:
  name: mysql
  namespace: mysql
spec:
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
        - name: mysql
          image: mysql:5.7
          env:
            - name: MYSQL_ROOT_PASSWORD
              value: "123"
            - name: MYSQL_DATABASE
              value: discuz
          livenessProbe:
            exec:
              command:
                - "/bin/sh"
                - "-c"
                - "cat /etc/mysql/my.cnf"
            initialDelaySeconds: 0
            periodSeconds: 3
            timeoutSeconds: 1
            successThreshold: 1
            failureThreshold: 3
          readinessProbe:
            tcpSocket:
              port: 3306
            initialDelaySeconds: 30
            periodSeconds: 1
            timeoutSeconds: 1
            successThreshold: 3
            failureThreshold: 1
---
kind: Service
apiVersion: v1
metadata:
  name: mysql
  namespace: mysql
spec:
  ports:
    - port: 3306
      targetPort: 3306
      protocol: TCP
      name: mysql
  selector:
    app: mysql
# 2、编写web.yaml
[root@k8s-m-01 discuz]# vim web.yaml 
kind: Namespace
apiVersion: v1
metadata:
  name: web
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
  namespace: web
spec:
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
        - name: php
          image: registry.cn-shanghai.aliyuncs.com/aliyun_mm/discuz:php-v2
          imagePullPolicy: Always
          livenessProbe:
            exec:
              command:
                - "/bin/sh"
                - "-c"
                - "cat /etc/php-fpm.d/www.conf"
            initialDelaySeconds: 0
            periodSeconds: 3
            timeoutSeconds: 1
            successThreshold: 1
            failureThreshold: 3
          readinessProbe:
            tcpSocket:
              port: 9000
            initialDelaySeconds: 10
            periodSeconds: 1
            timeoutSeconds: 1
            successThreshold: 3
            failureThreshold: 1
        - name: nginx
          image: registry.cn-shanghai.aliyuncs.com/aliyun_mm/discuz:nginx-v2
          imagePullPolicy: Always
          livenessProbe:
            exec:
              command:
                - "/bin/sh"
                - "-c"
                - "cat /etc/nginx/nginx.conf"
            initialDelaySeconds: 0
            periodSeconds: 3
            timeoutSeconds: 1
            successThreshold: 1
            failureThreshold: 3
          readinessProbe:
            tcpSocket:
              port: 80
            initialDelaySeconds: 30
            periodSeconds: 1
            timeoutSeconds: 1
            successThreshold: 3
            failureThreshold: 1
---
kind: Service
apiVersion: v1
metadata:
  name: web
  namespace: web
spec:
  ports:
    - port: 80
      targetPort: 80
      protocol: TCP
      name: http
  selector:
    app: web
  type: NodePort

4、生成aml文件

# 1、生成yaml文件
[root@k8s-m-01 discuz]# kubectl apply -f web.yaml 
[root@k8s-m-01 discuz]# kubectl apply -f mysql.yaml
# 2、查看
[root@k8s-m-01 discuz]# kubectl get pod -n web
NAME                   READY   STATUS    RESTARTS   AGE
web-7f897d448c-9hr26   2/2     Running   0          16m
[root@k8s-m-01 discuz]# kubectl get pod -n mysql
NAME                     READY   STATUS    RESTARTS   AGE
mysql-6f9b947c9f-vs5rv   1/1     Running   0          30m
[root@k8s-m-01 discuz]# kubectl get svc -n web web 
NAME   TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
web    NodePort   10.98.114.209   <none>        80:32263/TCP   30m
# 3、IP访问
192.168.15.111.32263

5、故障排查

# 1、报css错误,连接不上css
[root@k8s-m-01 discuz]# kubectl cp -n web web-7f897d448c-b67pk:/usr/share/nginx/html . -c php 
# 2、把discuz包重新生成并上传
与前面类似,略过
# 3、删除web的pod,让其自己生成
[root@k8s-m-01 discuz]# kubectl delete pod -n web web-7f897d448c-9hr26

在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值