k8s 배치 wordpress

26196 단어 쿠 베 넷 스
nginx 미 러 만 들 기
docker pull centos:7.6.1810
docker run -it --name nginx centos:7.6.1810 /bin/bash

yum install epel-release
yum 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_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

미 러 제출
docker commit b8e1e0ea8c1d mynginx:v1

php 미 러 만 들 기
docker run -it --name php centos:7.6.1810 /bin/bash

yum install epel-release -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

vi /etc/php-fpm.conf
error_log = /data/logs/php/error.log
daemonize = no

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

미 러 제출
docker commit 3350eef95741 myphp:v1

코드
-rw-r--r--  1 root root   151 Jul  1 22:29 Dockerfile
-rw-r--r--  1 root root   405 Jul  1 22:09 index.php
-rw-r--r--  1 root root 19915 Jul  1 22:09 license.txt
-rw-r--r--  1 root root  7278 Jul  1 22:09 readme.html
-rw-r--r--  1 root root  6912 Jul  1 22:09 wp-activate.php
drwxr-xr-x  9 root root  4096 Jul  1 22:09 wp-admin
-rw-r--r--  1 root root   351 Jul  1 22:09 wp-blog-header.php
-rw-r--r--  1 root root  2332 Jul  1 22:09 wp-comments-post.php
-rw-r--r--  1 root root  2913 Jul  1 22:09 wp-config-sample.php
drwxr-xr-x  4 root root    52 Jul  1 22:09 wp-content
-rw-r--r--  1 root root  3940 Jul  1 22:09 wp-cron.php
drwxr-xr-x 21 root root  8192 Jul  1 22:09 wp-includes
-rw-r--r--  1 root root  2496 Jul  1 22:09 wp-links-opml.php
-rw-r--r--  1 root root  3300 Jul  1 22:09 wp-load.php
-rw-r--r--  1 root root 47874 Jul  1 22:09 wp-login.php
-rw-r--r--  1 root root  8509 Jul  1 22:09 wp-mail.php
-rw-r--r--  1 root root 19396 Jul  1 22:09 wp-settings.php
-rw-r--r--  1 root root 31111 Jul  1 22:09 wp-signup.php
-rw-r--r--  1 root root  4755 Jul  1 22:09 wp-trackback.php
-rw-r--r--  1 root root  3133 Jul  1 22:09 xmlrpc.php

nginx - wordpress 미 러 제작
cat Dockerfile
FROM mynginx:v1
MAINTAINER 1226032602 [email protected]
RUN mkdir -p /data/www/wordpress
ADD . /data/www/wordpress
EXPOSE 80
ENTRYPOINT ["/usr/sbin/nginx"]
docker build . -t nginx-wordpress:v1
docker tag nginx-wordpress:v1 harbor.od.com/public/nginx-wordpress:v1
docker 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:v1
MAINTAINER 1226032602 [email protected]
RUN mkdir -p /data/www/wordpress
ADD . /data/www/wordpress
ENTRYPOINT ["/usr/sbin/php-fpm","-R"]
docker build . -t php-wordpress:v1
docker tag php-wordpress:v1 harbor.od.com/public/php-wordpress:v1
docker push harbor.od.com/public/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

배치 하 다.
cat 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: nginx
        image: harbor.od.com/public/nginx-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
      - name: php
        image: harbor.od.com/public/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: wordpress
          mountPath: /data/www/wordpress
        - name: wp-config
          mountPath: /data/www/wordpress/wp-config.php
          subPath: wp-config.php

cat wordpress-svc.yaml
apiVersion: v1
kind: Service
metadata:
  name: wordpress
  namespace: default
  labels:
    k8s-app: wordpress
spec:
  selector:
    k8s-app: wordpress
  type: NodePort
  ports:
  - name: wordpressport
    protocol: TCP
    port: 81
    targetPort: 80
docker login --username=dong1226032602 registry.cn-hangzhou.aliyuncs.com



docker tag mynginx:v1 registry.cn-hangzhou.aliyuncs.com/wuxingge/mynginx:v1
docker push registry.cn-hangzhou.aliyuncs.com/wuxingge/mynginx:v1


docker tag myphp:v1 registry.cn-hangzhou.aliyuncs.com/wuxingge/myphp:v1
docker push registry.cn-hangzhou.aliyuncs.com/wuxingge/myphp:v1



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



docker tag php-wordpress:v1 registry.cn-hangzhou.aliyuncs.com/wuxingge/php-wordpress:v1
docker 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/wordpress
kubectl exec wordpress-6bfb9464db-xvkqh -c php -- ls -l /data/www/wordpress

좋은 웹페이지 즐겨찾기