k8s部署wordpress-2

制作nginx-php镜像

docker run -it --name nginx-php centos:7.6.1810 /bin/bash

yum install epel-release
yum install nginx net-tools -y
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

yum 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

nginx配置

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_format  main  '$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.log  main;


    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;


    include             /etc/nginx/mime.types;
    default_type        application/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

php配置

vi /etc/php-fpm.conf

error_log = /data/logs/php/error.log

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

user = root
group = root
listen = /dev/shm/php-fpm.sock
listen.owner = root
listen.group = root
slowlog = /data/logs/php/www-slow.log
php_admin_value[error_log] = /data/logs/php/www-error.log
mkdir /data/logs/php -p

提交nginx-php镜像

docker commit 6633175310e0 my-nginx-php:v1

nginx-php-wordpress镜像制作

vi wordpress_entrypoint.sh

#!/bin/bash
/usr/sbin/php-fpm -R && \
exec "/usr/sbin/nginx"

vi Dockerfile

FROM my-nginx-php:v1
MAINTAINER 1226032602 [email protected]
RUN mkdir -p /data/www/wordpress
ADD . /data/www/wordpress
ADD wordpress_entrypoint.sh /wordpress_entrypoint.sh
RUN rm -f /data/www/wordpress/wordpress_entrypoint.sh
EXPOSE 80
ENTRYPOINT ["/wordpress_entrypoint.sh"]
docker build . -t nginx-php-wordpress:v1
docker tag nginx-php-wordpress:v1 harbor.od.com/public/nginx-php-wordpress:v1
docker push harbor.od.com/public/nginx-php-wordpress:v1

configMap

vi nginx-wordpress-configmap.yaml

apiVersion: v1
data:
  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: ConfigMap
metadata:
  name: nginxconf
  namespace: default

vi wp-config.yaml

apiVersion: v1
data:
  wp-config.php: |
    
    
    // ** 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]H]!UrDQg]Qw0 );
    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[If`5I8{=d(yqi:rF%bb0 -}eL8b7huo8M' );
    define( 'NONCE_SALT',       ']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: ConfigMap
metadata:
  name: wp-config
  namespace: default

deployment

vi wordpress-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: wordpress
  namespace: default
  labels:
    k8s-app: wordpress
spec:
  replicas: 1
  selector:
    matchLabels:
      k8s-app: wordpress
  template:
    metadata:
      labels:
        k8s-app: wordpress
    spec:
      volumes:
      - name: nginx-conf
        configMap:
          name: nginxconf
      - name: wordpress
        nfs: 
          server: hdss7-200
          path: /data/nfs-volume/wordpress
      - name: wp-config
        configMap:
          name: wp-config
      containers:
      - name: wordpress
        image: harbor.od.com/public/nginx-php-wordpress:v1
        resources:
          limits:
            cpu: 500m
            memory: 1Gi
          requests:
            cpu: 250m
            memory: 256Mi
        env:
        - name: PATH
          value: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
        volumeMounts:
        - name: nginx-conf
          mountPath: /etc/nginx/conf.d/
        - name: wordpress
          mountPath: /data/www/wordpress
        - name: wp-config
          mountPath: /data/www/wordpress/wp-config.php
          subPath: wp-config.php

service

vi wordpress-svc.yaml

kind: Service
apiVersion: v1
metadata:
  name: wordpress
  namespace: default
  labels:
    k8s-app: wordpress
spec:
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
  selector:
    k8s-app: wordpress

ingress

vi wordpress-ingress.yaml

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: wordpress
  namespace: default
spec:
  rules:
  - host: wordpress.od.com
    http:
      paths:
      - path: /
        backend:
          serviceName: wordpress
          servicePort: 80

docker login --username=dong1226032602 registry.cn-hangzhou.aliyuncs.com


docker tag my-nginx-php:v1 registry.cn-hangzhou.aliyuncs.com/wuxingge/my-nginx-php:v1
docker push registry.cn-hangzhou.aliyuncs.com/wuxingge/my-nginx-php:v1


docker tag nginx-php-wordpress:v1 registry.cn-hangzhou.aliyuncs.com/wuxingge/nginx-php-wordpress:v1
docker push registry.cn-hangzhou.aliyuncs.com/wuxingge/nginx-php-wordpress:v1

你可能感兴趣的:(kubernetes)