部署架构图
准备PHP镜像-官方基础镜像
cd learning-k8s/01-jiege/k8s-data/dockerfile/web/magedu/wordpress
#PHP Base Image
#FROM harbor.magedu.net/baseimages/magedu-centos-base:7.9.2009
FROM harbor.linuxarchitect.io/baseimages/magedu-centos-base:7.9.2009
MAINTAINER xxx@magedu.net
RUN yum install -y https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-7.rpm && yum install php56-php-fpm php56-php-mysql -y
ADD www.conf /opt/remi/php56/root/etc/php-fpm.d/www.conf
#RUN useradd nginx -u 2019
ADD run_php.sh /usr/local/bin/run_php.sh
EXPOSE 9000
CMD ["/usr/local/bin/run_php.sh"]
#!/bin/bash
TAG=$1
docker build -t harbor.linuxarchitect.io/magedu/wordpress-php-5.6:${TAG} .
#nerdctl build -t harbor.magedu.net/magedu/wordpress-php-5.6:${TAG} .
echo "镜像制作完成,即将上传至Harbor服务器"
sleep 1
#nerdctl push harbor.magedu.net/magedu/wordpress-php-5.6:${TAG}
docker push harbor.linuxarchitect.io/magedu/wordpress-php-5.6:${TAG}
echo "镜像上传完成"
输出wordpress-php镜像
准备Nginx镜像-官方基础镜像
cd learning-k8s/01-jiege/k8s-data/dockerfile/web/magedu/wordpress
#FROM harbor.magedu.local/pub-images/nginx-base-wordpress:v1.20.2
FROM harbor.linuxarchitect.io/pub-images/nginx-base-wordpress:v1.22.0
ADD nginx.conf /apps/nginx/conf/nginx.conf
ADD run_nginx.sh /apps/nginx/sbin/run_nginx.sh
RUN mkdir -pv /home/nginx/wordpress
RUN chown nginx.nginx /home/nginx/wordpress/ -R
EXPOSE 80 443
CMD ["/apps/nginx/sbin/run_nginx.sh"]
#!/bin/bash
TAG=$1
docker build -t harbor.linuxarchitect.io/magedu/wordpress-nginx:${TAG} .
#nerdctl build -t harbor.magedu.net/magedu/wordpress-nginx:${TAG} .
echo "镜像制作完成,即将上传至Harbor服务器"
sleep 1
#nerdctl push harbor.magedu.net/magedu/wordpress-nginx:${TAG}
docker push harbor.linuxarchitect.io/magedu/wordpress-nginx:${TAG}
echo "镜像上传完成"
输出 wordpress-nginx镜像
运行wordpress
kind: Deployment
#apiVersion: extensions/v1beta1
apiVersion: apps/v1
metadata:
labels:
app: wordpress-app
name: wordpress-app-deployment
namespace: magedu
spec:
replicas: 1
selector:
matchLabels:
app: wordpress-app
template:
metadata:
labels:
app: wordpress-app
spec:
containers:
- name: wordpress-app-nginx
image: harbor.linuxarchitect.io/magedu/wordpress-nginx:v2
imagePullPolicy: Always
ports:
- containerPort: 80
protocol: TCP
name: http
- containerPort: 443
protocol: TCP
name: https
volumeMounts:
- name: wordpress
mountPath: /home/nginx/wordpress
readOnly: false
- name: wordpress-app-php
image: harbor.linuxarchitect.io/magedu/wordpress-php-5.6:v1
#image: harbor.magedu.net/magedu/php:5.6.40-fpm
#imagePullPolicy: IfNotPresent
imagePullPolicy: Always
ports:
- containerPort: 9000
protocol: TCP
name: http
volumeMounts:
- name: wordpress
mountPath: /home/nginx/wordpress
readOnly: false
volumes:
- name: wordpress
nfs:
server: 172.31.7.109
path: /data/k8sdata/magedu/wordpress
---
kind: Service
apiVersion: v1
metadata:
labels:
app: wordpress-app
name: wordpress-app-spec
namespace: magedu
spec:
type: NodePort
ports:
- name: http
port: 80
protocol: TCP
targetPort: 80
nodePort: 30031
- name: https
port: 443
protocol: TCP
targetPort: 443
nodePort: 30033
selector:
app: wordpress-app