一、部署wordpress
1、构建镜像 2、构思架构,同时编写配置清单
3、部署
创建mysql的命名空间
[root@k8s-master-01 wordpress]
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]
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 ~]
[root@k8s-m-01 ~]
[root@k8s-m-01 discuz]
[root@k8s-m-01 discuz]
2、构建nginx
[root@k8s-m-01 nginx]
[root@k8s-m-01 nginx]
[root@k8s-m-01 nginx]
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;
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]
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;
}
}
[root@k8s-m-01 nginx]
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;"]
[root@k8s-m-01 nginx]
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
[root@k8s-m-01 nginx]
[root@k8s-m-01 nginx]
3、构建php
[rook8s-m-01 php]
[rook8s-m-01 php]
[root@k8s-m-01 php]
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
[root@k8s-m-01 php]
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
[root@k8s-m-01 nginx]
[root@k8s-m-01 nginx]
3、编写yaml文件
[root@k8s-m-01 discuz]
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
[root@k8s-m-01 discuz]
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文件
[root@k8s-m-01 discuz]
[root@k8s-m-01 discuz]
[root@k8s-m-01 discuz]
NAME READY STATUS RESTARTS AGE
web-7f897d448c-9hr26 2/2 Running 0 16m
[root@k8s-m-01 discuz]
NAME READY STATUS RESTARTS AGE
mysql-6f9b947c9f-vs5rv 1/1 Running 0 30m
[root@k8s-m-01 discuz]
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
web NodePort 10.98.114.209 <none> 80:32263/TCP 30m
192.168.15.111.32263
5、故障排查
[root@k8s-m-01 discuz]
与前面类似,略过
[root@k8s-m-01 discuz]
|