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博客可玩性很高,但刚开始只想练练手,就没有想买域 ...
随机推荐
- git push The requested URL returned error: 403 Forbidden while accessing
错误提示信息: error: The requested URL returned error: Forbidden while accessing https://github.com/xingfu ...
- SOFA 源码分析— 自定义路由寻址
前言 SOFA-RPC 中对服务地址的选择也抽象为了一条处理链,由每一个 Router 进行处理.同 Filter 一样, SOFA-RPC 对 Router 提供了同样的扩展能力. 那么就看看 SO ...
- thinkphp---ajax实现删除
$(document).ready(function(){ $("a[data]").click(function(){ var data = $(this).attr('data ...
- 用Promise实现:带延时功能的链式调用
// 1) 调用方式 new People('whr').sleep(3).eat('apple').sleep(5).eat('durian'); // 2) 打印结果 'hello, whr' - ...
- EasyUI集成Kindeditor使用
在实际的项目中,我们需要在项目中集成富文本编辑器,而kindeditor作为一款优良的编辑器,在项目中或多或少都会用到! 实际效果图 使用方法: 1.首先下载Kindeditor编辑器,我这里 ...
- java中Iterator和ListIterator的区别与联系
首先,为什么需要使用迭代器Iterator,原有的for循环和for each不能满足需求吗? 那是因为Iterator模式是用于遍历集合类的标准访问方法.它可以把访问逻辑从不同类型的集合类中抽象出来 ...
- 设置ActiveMQ的访问密码
1.设置ActiveMQ的访问密码,以提高ActiveMQ的安全性 2.在ActiveMQ的conf目录的activemq.xml中添加账号密码 2.1 添加的代码如下 <!-- 添加访问Ac ...
- SSM-Spring-22:Spring+Mybatis+JavaWeb的整合
------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 众所周知,框架Spring来整合别的框架,但是Mybatis出现的晚,Spring就没有给他提供支持,那怎么办 ...
- Centos下的apache2练习
前言: 我上星期一直在写代码忘记写博客了,明天回去补回来.脚本主要用于收集信息 今天刚刚学完apache.来做个总结,写的不好请多多指指出. 目标: Centos6.5的IP:192.168.1.21 ...
- Activity的运行过程
今天看到了这个关于Activity的过程这个方面的知识,之前我其实也是做过安卓项目的,也是有安卓开发的一定经验的,但是我发现之前似乎是知其然,而不知其所以然,之前来说只知道activity里的onCr ...