k8s经典实战—搭建WordPress
k8s经典实战—搭建WordPress
说明:需要在k8s上部署lnmp环境,建议跟着步骤来端口最好不要改,希望你也能搭建成功,完成这个搭建后你对Kubernetes的技术基本上是入门了。首先看下效果图:
一、部署存储用户持久化存储
1. 准备一块100G磁盘做为LVM逻辑卷(参考:https://www.cnblogs.com/Dev0ps/p/9381244.html)
fdisk -l
fdisk /dev/vdb
mkdir /u01
pvcreate /dev/vdb1
vgcreate vg0 /dev/vdb1
lvcreate -L 99G -n oralv vg0
mkfs.ext4 /dev/vg0/oralv
mount /dev/vg0/oralv /u01/
echo "/dev/vg0/oralv /u01 ext4 defaults 0 0" >>/etc/fstab
用df -h 命令查看:
2、搭建NFS共享存储
2.1 nfs服务端
yum install nfs-utils -y
mkdir -pv /u01/nps/volumes
vim /etc/exports
/u01/nps/volumes 172.31.182.0/24(rw,no_root_squash)
systemctl start nfs
查看服务是否开启
2.2 创建nps挂载目录
mkdir -pv /u01/nps/volumes/data{mysql,nginx}
2.3 nfs客户端(k8s的node节点都需要安装)
yum install nfs-utils -y
#验证是否可以访问nfs服务端
[root@node01 ~]# showmount -e 172.31.182.145
Export list for 172.31.182.145:
/u01/nps/volumes 172.31.182.0/24
[root@node01 ~]# mount -t nfs 172.31.182.145:/u01/nps/volumes /mnt
echo "172.31.182.145:/u01/nps/volumes /mnt nfs defaults 0 0" >>/etc/fstab
二、创建pv
[root@master Dockerfile-lnmp]# cat pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: mysql-pv
spec:
capacity:
storage: 20Gi
accessModes:
- ReadWriteMany
nfs:
path: /u01/nps/volumes/data/mysql
server: 172.31.182.145
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: wp-pv01
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteMany
nfs:
path: /u01/nps/volumes/data/nginx
server: 172.31.182.145
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: wp-pv02
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteMany
nfs:
path: /u01/nps/volumes/data/nginx
server: 172.31.182.145
创建pv:
kubectl apply -f pv.yaml
三、部署mysql
3.1 创建mysql-deployment
[root@master Dockerfile-lnmp]# cat mysql-deployment.yaml
apiVersion: v1
kind: Service
metadata:
name: wordpress-mysql
labels:
app: wordpress
spec:
ports:
- port: 3306
selector:
app: wordpress
tier: mysql
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pv-claim
labels:
app: wordpress
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 20Gi
---
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: wordpress-mysql
labels:
app: wordpress
spec:
selector:
matchLabels:
app: wordpress
tier: mysql
strategy:
type: Recreate
template:
metadata:
labels:
app: wordpress
tier: mysql
spec:
containers:
- name: mysql
spec:
containers:
- name: mysql
image: mysql:5.6
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-pass
key: password
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- mountPath: "/var/lib/mysql"
name: mysql-data
volumes:
- name: mysql-data
persistentVolumeClaim:
claimName: mysql-pv-claim
创建mysql容器:
kubectl apply -f mysql-deployment.yaml
3.2 通过secret创建mysql密码
kubectl create secret generic mysql-pass --from-literal=password=123456
四、上传镜像到Harbor
4.1 构建nginx镜像并上传
[root@master nginx]# docker build -t 172.31.182.143/dev/nginx:latest .
[root@master nginx]# docker push 172.31.182.143/dev/nginx:latest
4.2 构建php镜像并上传
[root@master php]# docker build -t 172.31.182.143/dev/php:latest .
[root@master php]# docker push 172.31.182.143/dev/php:latest
4.3 kubernetes配置Harbor仓库
kubectl create secret docker-registry regcred --docker-server=172.31.182.143 --docker-username=admin --docker-password=Harbor%12345 --docker-email=admin@qq.com
注意!!上述由于没有指定namespace默认会在default命名空间下创建secret,如果是别的ns需在后面指定如:-n test 否则test命名空间下的pod仍然无法拉取私有仓库镜像。
五、部署php环境
5.1 创建php-deployment
[root@master Dockerfile-lnmp]# cat php-deployment.yaml
apiVersion: v1
kind: Service
metadata:
name: wordpress-php
labels:
app: wordpress
spec:
ports:
- port: 9000
selector:
app: wordpress-php
tier: frontend
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wp-pvc01
labels:
app: wordpress
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 5Gi
---
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: wordpress-php
labels:
app: wordpress
spec:
replicas: 3
selector:
matchLabels:
app: wordpress-php
tier: frontend
strategy:
type: Recreate
template:
metadata:
labels:
app: wordpress-php
tier: frontend
spec:
imagePullSecrets:
- name: regcred
containers:
- name: php
image: 172.31.182.143/dev/php:latest
ports:
- containerPort: 9000
name: wordpress
volumeMounts:
- name: php-data
mountPath: "/usr/local/nginx/html"
volumes:
- name: php-data
persistentVolumeClaim:
claimName: wp-pvc01
注意:在yaml文件中需加入secret用于访问镜像仓库。
imagePullSecrets:
- name: regcred
创建php容器:
kubectl apply -f php-deployment.yaml
六、部署nginx环境
6.1 创建nginx-deployment
[root@master Dockerfile-lnmp]# cat nginx-deployment.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-wp-config
data:
site.conf: |-
server {
listen 80;
server_name localhost;
root html;
index index.php index.html; location ~ \.php$ {
root html;
fastcgi_pass wordpress-php:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
---
apiVersion: v1
kind: Service
metadata:
name: wordpress-nginx
labels:
app: wordpress
spec:
ports:
- port: 80
selector:
app: wordpress-nginx
tier: frontend
type: NodePort
sessionAffinity: ClientIP
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wp-pvc02
labels:
app: wordpress
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 5Gi
---
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: wordpress-nginx
labels:
app: wordpress
spec:
replicas: 3
selector:
matchLabels:
app: wordpress-nginx
tier: frontend
strategy:
type: Recreate
template:
metadata:
labels:
app: wordpress-nginx
tier: frontend
spec:
imagePullSecrets:
- name: regcred
containers:
- name: nginx
image: 172.31.182.143/dev/nginx:latest
ports:
- containerPort: 80
name: wordpress
volumeMounts:
- mountPath: "/usr/local/nginx/html"
name: nginx-data
- mountPath: "/usr/local/nginx/conf/vhost/site.conf"
name: config
subPath: site.conf
volumes:
- name: nginx-data
persistentVolumeClaim:
claimName: wp-pvc02
- name: config
configMap:
name: nginx-wp-config
创建nginx容器:
kubectl apply -f nginx-deployment.yaml
七、查看pod,svc,pv,pvc,secret的状态
7.1 kubectl get pod
7.2 kubectl get svc
我这里wordpress-nginx的NodePort随机生成是47074,访问时改为你们自己生成的即可!!
7.3 kubectl get pv,pvc
7.4 kubectl get secret
八、创建wordpress数据库
[root@master nginx]# kubectl exec -it wordpress-mysql-68cb6cc5b4-xxfhh bash
root@wordpress-mysql-68cb6cc5b4-xxfhh:/# mysql -uroot -p123456
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 105
Server version: 5.6.43 MySQL Community Server (GPL) Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> create database wordpress;
九、设置WordPress
9.1 解压WordPress安装包到nginx的挂载目录下:
访问地址为:http://nodeIP:nodePort//wordpress/index.php
9.2 配置相关信息,这里注意数据库主机就是mysql的service:wordpress-mysql
9.3 提交后设置账号密码,一个熟悉的wordpress就出现在我们面前,啧啧啧。。。
搭建博客用到的yaml文件及安装包可在以下地址获取:https://github.com/hejianlai/Docker-Kubernetes/tree/master/Kubernetes/Project/k8s_wordporss
k8s经典实战—搭建WordPress的更多相关文章
- 阿里云centos7搭建wordpress环境
阿里云搭建wordpress系统 一.购买阿里云 二.安装php开发环境 1. https://www.apachefriends.org/zh_cn/index.html网站下载linux下的xam ...
- 烂泥:使用nginx利用虚拟主机搭建WordPress博客
本文由秀依林枫提供友情赞助,首发于烂泥行天下. 最近开始打算学习nginx web服务器,既然是学习还是以实用为目的的.我们在此以搭建WordPress博客为例. 搭建WordPress博客,我们需要 ...
- [Linux] Ubuntu Server 12.04 LTS 平台上搭建WordPress(Nginx+MySql+PHP) Part II
接着上一节继续搭建我们的LNMP平台,接下来我们安装PHP相关的服务 sudo apt-get install php5-cli php5-cgi php5-fpm php5-mcrypt php5- ...
- [Linux] Ubuntu Server 12.04 LTS 平台上搭建WordPress(Nginx+MySQL+PHP) Part IV
接下来我们去下载 WorePress 用最新的 3.7.1 下载地址是:http://cn.wordpress.org/wordpress-3.7.1-zh_CN.zip 我们先建立一个文件夹 /va ...
- 【阿里云产品公测】云引擎ACE新手实战基于Wordpress
[阿里云产品公测]云引擎ACE新手实战基于Wordpress 作者:阿里云用户imnpc ACE(Aliyun Cloud Engine) 是一款弹性.分布式的应用托管环境,支持Java.php多种语 ...
- SAE搭建WordPress教程 免费建WordPress博客站
SAE搭建WordPress教程 免费建WordPress博客站 WordPress是一种使用PHP语言开发的博客平台,用户可以在支持PHP和MySQL数据库的服务器上架设自己的网志.当然,用户也可以 ...
- SAE 搭建 WordPress
WordPress,是国外一款使用PHP语言开发的开源博客平台,用户可以在支持PHP和MySQL 数据库的服务器上架设自己的博客站点,也可以把 WordPress 当作一个内容管理系统(CMS)来使用 ...
- LAMP 搭建wordpress部署教程贴.
LAMP 搭建wordpress部署教程贴.这是一篇主要将LAMP,并且通过wordpress来进行验证,演示.如何去部署PHP CMS很多新手看到LAMP就很很头大,觉得很难搞,编译安装,搞了好几天 ...
- 免费搭建wordpress博客有感
之前一直有搭建个wordpress博客的想法,但一直没有实施.最近离职之后,空闲时间多了起来,就开始折腾wordpress博客起来. wordpress博客可玩性很高,但刚开始只想练练手,就没有想买域 ...
随机推荐
- SpringBoot 创建可执行Jar
创建可执行JAR 我们也可以通过插件创建一个在生产环境中运行的可执行jar文件来完成我们的示例. 首先引入依赖: <build> <plugins> <plugin> ...
- 算法训练 2的次幂表示(蓝桥杯C++写法)
问题描述 任何一个正整数都可以用2进制表示,例如:137的2进制表示为10001001. 将这种2进制表示写成2的次幂的和的形式,令次幂高的排在前面,可得到如下表达式:137=2^7+2^3+2^0 ...
- TCP分组交换详解
TCP(Transmission Control Protocol) 传输控制协议 TCP是主机对主机层的传输控制协议,提供可靠的连接服务,采用三次握手确认建立一个连接: 位码即tcp标志位,有6种标 ...
- Vue初学跳坑
1. uncaught TypeError: Cannot read property '0' of undefined <div class="home-module-wrap&qu ...
- IntelliJ IDEA添加jar包
以JDBC-MySQL驱动包为例 1.在IntelliJ IDEA中打开要添加jar包的Project 2.File – Project Structure如下图 3.选择Moudules – 再选择 ...
- SSM-SpringMVC-24:SpringMVC异常高级之自定义异常
------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 自定义异常,大家都会,对吧,无非就是继承异常类等操作,很简单,我就不多扯皮了,但是在xml配置文件中有个不同的 ...
- MVP架构在xamarin android中的简单使用
好几个月没写文章了,使用xamarin android也快接近两年,还有一个月职业生涯就到两个年了,从刚出来啥也不会了,到现在回头看这个项目,真jb操蛋(真辛苦了实施的人了,无数次吐槽怎么这么丑),怪 ...
- backbone的一些认识
body,td { font-family: 微软雅黑; font-size: 10pt } 官网:http://backbonejs.org/ 作者:Jeremy Ashkenas 杰里米·阿什肯纳 ...
- spring boot -Properties & configuration
72. Properties & configuration72.1 Automatically expand properties at build timeRather than hard ...
- JavaWeb(一)JavaWeb应用的概念
JavaWeb应用的概念 在Sun的Java Servlet规范中,对Java Web应用作了这样定义:"Java Web应用由一组Servlet.HTML页.类.以及其它可以被绑定的资源构 ...