k8s 部署wordpress
2022-07-29 10:13:20
131
{{single.collect_count}}

制作nginx镜像

docker pull centos:7.6.1810docker run -it --name nginx centos:7.6.1810 /bin/bashyum install epel-releaseyum install nginx net-tools -y

vi /etc/nginx/nginx.conf

user root;daemon off;worker_processes auto;error_log /var/log/nginx/error.log;pid /run/nginx.pid;# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.include /usr/share/nginx/modules/*.conf;events {worker_connections 1024;}http {log_formatmain'$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';access_log/data/logs/nginx/access.logmain;sendfileon;tcp_nopushon;tcp_nodelay on;keepalive_timeout 65;types_hash_max_size 2048;include /etc/nginx/mime.types;default_typeapplication/octet-stream;# Load modular configuration files from the /etc/nginx/conf.d directory.# See http://nginx.org/en/docs/ngx_core_module.html#include# for more information.include /etc/nginx/conf.d/*.conf;}

vi /etc/nginx/conf.d/localhost.conf

server {listen 80;server_name wordpress.tencent.com localhost;error_log /data/logs/nginx/wordpress.tencent.com_error.log error;root /data/www/wordpress;index index.php;location / {try_files $uri $uri/ /index.php?$query_string;}location ~ \.php$ {include fastcgi.conf;fastcgi_pass unix:/dev/shm/php-fpm.sock;}}

创建目录

mkdir /data/logs/nginx -p

提交镜像

docker commit b8e1e0ea8c1d mynginx:v1

制作php镜像

docker run -it --name php centos:7.6.1810 /bin/bashyum install epel-release -yrpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpmyum install php70w php70w-fpm php70w-cli php70w-common php70w-devel php70w-gd php70w-pdo php70w-mysql php70w-mbstring php70w-bcmath php70w-xml php70w-peclredis php70w-process php70w-intl php70w-xmlrpc php70w-soap php70w-ldap php70w- opcache -y

vi /etc/php-fpm.conf

error_log = /data/logs/php/error.logdaemonize = no

vi /etc/php-fpm.d/www.conf

user = rootgroup = rootlisten = /dev/shm/php-fpm.socklisten.owner = rootlisten.group = rootslowlog = /data/logs/php/www-slow.logphp_admin_value[error_log] = /data/logs/php/www-error.log

创建目录

mkdir /data/logs/php -p

提交镜像

docker commit 3350eef95741 myphp:v1

代码

-rw-r--r--1 root root 151 Jul1 22:29 Dockerfile-rw-r--r--1 root root 405 Jul1 22:09 index.php-rw-r--r--1 root root 19915 Jul1 22:09 license.txt-rw-r--r--1 root root7278 Jul1 22:09 readme.html-rw-r--r--1 root root6912 Jul1 22:09 wp-activate.phpdrwxr-xr-x9 root root4096 Jul1 22:09 wp-admin-rw-r--r--1 root root 351 Jul1 22:09 wp-blog-header.php-rw-r--r--1 root root2332 Jul1 22:09 wp-comments-post.php-rw-r--r--1 root root2913 Jul1 22:09 wp-config-sample.phpdrwxr-xr-x4 root root52 Jul1 22:09 wp-content-rw-r--r--1 root root3940 Jul1 22:09 wp-cron.phpdrwxr-xr-x 21 root root8192 Jul1 22:09 wp-includes-rw-r--r--1 root root2496 Jul1 22:09 wp-links-opml.php-rw-r--r--1 root root3300 Jul1 22:09 wp-load.php-rw-r--r--1 root root 47874 Jul1 22:09 wp-login.php-rw-r--r--1 root root8509 Jul1 22:09 wp-mail.php-rw-r--r--1 root root 19396 Jul1 22:09 wp-settings.php-rw-r--r--1 root root 31111 Jul1 22:09 wp-signup.php-rw-r--r--1 root root4755 Jul1 22:09 wp-trackback.php-rw-r--r--1 root root3133 Jul1 22:09 xmlrpc.php

nginx-wordpress镜像制作

cat Dockerfile

FROM mynginx:v1MAINTAINER 1226032602 1226032602@qq.comRUN mkdir -p /data/www/wordpressADD . /data/www/wordpressEXPOSE 80ENTRYPOINT ["/usr/sbin/nginx"]
docker build . -t nginx-wordpress:v1docker tag nginx-wordpress:v1 harbor.od.com/public/nginx-wordpress:v1docker push harbor.od.com/public/nginx-wordpress:v1

nfs

vim /etc/exports

/data/nfs-volume 10.4.7.0/24(rw,no_root_squash)

php-wordpress镜像制作

cat Dockerfile

FROM myphp:v1MAINTAINER 1226032602 1226032602@qq.comRUN mkdir -p /data/www/wordpressADD . /data/www/wordpressENTRYPOINT ["/usr/sbin/php-fpm","-R"]
docker build . -t php-wordpress:v1docker tag php-wordpress:v1 harbor.od.com/public/php-wordpress:v1docker push harbor.od.com/public/php-wordpress:v1

configMap

vi nginx-wordpress-configmap.yaml

apiVersion: v1data:localhost.conf: |server {listen 80;server_name wordpress.tencent.com localhost;error_log /data/logs/nginx/wordpress.tencent.com_error.log error;root /data/www/wordpress;index index.php;location / {try_files $uri $uri/ /index.php?$query_string;}location ~ \.php$ {include fastcgi.conf;fastcgi_pass unix:/dev/shm/php-fpm.sock;}}kind: ConfigMapmetadata:name: nginxconfnamespace: default

vi wp-config.yaml

apiVersion: v1data:wp-config.php: |<?php/** * The base configuration for WordPress * * The wp-config.php creation script uses this file during the * installation. You don't have to use the web site, you can * copy this file to "wp-config.php" and fill in the values. * * This file contains the following configurations: * * * MySQL settings * * Secret keys * * Database table prefix * * ABSPATH * * @link https://wordpress.org/support/article/editing-wp-config-php/ * * @package WordPress */// ** MySQL settings - You can get this info from your web host ** ///** The name of the database for WordPress */define( 'DB_NAME', 'wordpress' );/** MySQL database username */define( 'DB_USER', 'wordpress' );/** MySQL database password */define( 'DB_PASSWORD', '123456' );/** MySQL hostname */define( 'DB_HOST', '10.4.7.11' );/** Database Charset to use in creating database tables. */define( 'DB_CHARSET', 'utf8mb4' );/** The Database Collate type. Don't change this if in doubt. */define( 'DB_COLLATE', '' );/**#@+ * Authentication Unique Keys and Salts. * * Change these to different unique phrases! * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service} * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again. * * @since 2.6.0 */define( 'AUTH_KEY', '!j{}>)e}_k9M=D;lsoKR2o:FrvZ (ML+CK;<18R-%9IIU#r%/NdOz.Y.B%SChnO$' );define( 'SECURE_AUTH_KEY','Kr8-n 9OEy`RF4j`qoQaVS3%!/asg*-1VHK>x!WmO;P~w{2mZw5C!RS7x}r9W}se' );define( 'LOGGED_IN_KEY','Qe<*nE3kW_9@KqZ]F&~mz6B]{A<K48CWmk GWv*(]H]</pDxhQ+c!UrDQg]Qw0<D' );define( 'NONCE_KEY','n{bW`%=sogNl:~|_I:K69m#w075Jwc$=k?_=k2=!{|Gu%-,g]}i*:N;Co5_75?oo' );define( 'AUTH_SALT','%{#> oDDT#D???bD-;,|-3Qbv;:sUi<9h 1@,3oq25c:b9vKnH^&l1l5#?373_XV' );define( 'SECURE_AUTH_SALT', 'eOpRcCgvKl0gRol]cUj7rZklTI?z(>5+$rU5}1?6!itK)8 t-_|FF:[#S{@_xeo+' );define( 'LOGGED_IN_SALT', 'x40,tVmi~R}j7jqqM;Wy72nRMTc5<t[If`5I8{=d(yqi:rF%bb0 -}eL8b7huo8M' );define( 'NONCE_SALT', '<u1mfMb]xmuuJF)6JMd1I@$o9:VE6hx9{U=al`:;`JPU:BoNg-/OTtC8g.k%+F@A' );/**#@-*//** * WordPress Database Table prefix. * * You can have multiple installations in one database if you give each * a unique prefix. Only numbers, letters, and underscores please! */$table_prefix = 'wp_';/** * For developers: WordPress debugging mode. * * Change this to true to enable the display of notices during development. * It is strongly recommended that plugin and theme developers use WP_DEBUG * in their development environments. * * For information on other constants that can be used for debugging, * visit the documentation. * * @link https://wordpress.org/support/article/debugging-in-wordpress/ */define( 'WP_DEBUG', false );/* That's all, stop editing! Happy publishing. *//** Absolute path to the WordPress directory. */if ( ! defined( 'ABSPATH' ) ) {define( 'ABSPATH', __DIR__ . '/' );}/** Sets up WordPress vars and included files. */require_once ABSPATH . 'wp-settings.php';kind: ConfigMapmetadata:name: wp-confignamespace: default

部署

cat wordpress-deployment.yaml

apiVersion: apps/v1kind: Deploymentmetadata:name: wordpressnamespace: defaultlabels:k8s-app: wordpressspec:replicas: 1selector:matchLabels:k8s-app: wordpresstemplate:metadata:labels:k8s-app: wordpressspec:volumes:- name: nginx-confconfigMap:name: nginxconf- name: wordpressnfs: server: hdss7-200path: /data/nfs-volume/wordpress- name: wp-configconfigMap:name: wp-configcontainers:- name: nginximage: harbor.od.com/public/nginx-wordpress:v1resources:limits:cpu: 500mmemory: 1Girequests:cpu: 250mmemory: 256Mienv:- name: PATHvalue: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/binvolumeMounts:- name: nginx-confmountPath: /etc/nginx/conf.d/- name: wordpressmountPath: /data/www/wordpress- name: wp-configmountPath: /data/www/wordpress/wp-config.phpsubPath: wp-config.php- name: phpimage: harbor.od.com/public/php-wordpress:v1resources:limits:cpu: 500mmemory: 1Girequests:cpu: 250mmemory: 256Mienv:- name: PATHvalue: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/binvolumeMounts:- name: wordpressmountPath: /data/www/wordpress- name: wp-configmountPath: /data/www/wordpress/wp-config.phpsubPath: wp-config.php

cat wordpress-svc.yaml

apiVersion: v1kind: Servicemetadata:name: wordpressnamespace: defaultlabels:k8s-app: wordpressspec:selector:k8s-app: wordpresstype: NodePortports:- name: wordpressportprotocol: TCPport: 81targetPort: 80
docker login --username=dong1226032602 registry.cn-hangzhou.aliyuncs.comdocker tag mynginx:v1 registry.cn-hangzhou.aliyuncs.com/wuxingge/mynginx:v1docker push registry.cn-hangzhou.aliyuncs.com/wuxingge/mynginx:v1docker tag myphp:v1 registry.cn-hangzhou.aliyuncs.com/wuxingge/myphp:v1docker push registry.cn-hangzhou.aliyuncs.com/wuxingge/myphp:v1docker tag nginx-wordpress:v1 registry.cn-hangzhou.aliyuncs.com/wuxingge/nginx-wordpress:v1docker push registry.cn-hangzhou.aliyuncs.com/wuxingge/nginx-wordpress:v1docker tag php-wordpress:v1 registry.cn-hangzhou.aliyuncs.com/wuxingge/php-wordpress:v1docker push registry.cn-hangzhou.aliyuncs.com/wuxingge/php-wordpress:v1

kubectl 在pod的容器中执行命令

kubectl exec pod名称 -c 容器名称 -- 执行命令kubectl exec wordpress-6bfb9464db-xvkqh -c nginx -- ls -l /data/www/wordpresskubectl exec wordpress-6bfb9464db-xvkqh -c php -- ls -l /data/www/wordpress
回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}