Centos7通過Kubernetes+GlusterFS部署wordpress+mysql
阿新 • • 發佈:2019-01-09
操作環境
網路拓撲圖OS
CentOS Linux release 7.4.1708 (Core)
docker
kubernetesClient: Version: 1.12.6 API version: 1.24 Package version: docker-1.12.6-68.gitec8512b.el7.centos.x86_64 Go version: go1.8.3 Git commit: ec8512b/1.12.6 Built: Mon Dec 11 16:08:42 2017 OS/Arch: linux/amd64 Server: Version: 1.12.6 API version: 1.24 Package version: docker-1.12.6-68.gitec8512b.el7.centos.x86_64 Go version: go1.8.3 Git commit: ec8512b/1.12.6 Built: Mon Dec 11 16:08:42 2017 OS/Arch: linux/amd64
Kubernetes v1.5.2
glusterfs
glusterfs 3.12.3
操作步驟
這裡的配置步驟都是基於前幾篇文章來的,就不詳細說明了PV&PVC配置
1.編寫mysql pv yaml檔案如下:2.編寫mysql pvc yaml檔案如下:[[email protected] yaml]# vi glusterfs-pv.yaml apiVersion: v1 kind: PersistentVolume metadata: name: wordpress-mysql labels: name: mysql spec: capacity: storage: 20Gi accessModes: - ReadWriteMany glusterfs: endpoints: "glusterfs-cluster" path: "mysql-volume" readOnly: false
[[email protected] yaml]# vi glusterfs-pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wordpress-mysql-pvc
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 20Gi
selector:
matchLabels:
name: "mysql"
3.啟動上述2 檔案
[ [email protected] yaml]# kubectl apply -f glusterfs-pv.yaml
persistentvolume "wordpress-mysql" configured
[[email protected] yaml]# kubectl apply -f glusterfs-pvc.yaml
persistentvolumeclaim "wordpress-mysql-pvc" configured
4.編寫wordpress pv & pvc yaml配置檔案,這裡將2個寫在一起
[[email protected] yaml]# vi wordpress-pvc.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: wordpress-html
labels:
name: html
spec:
capacity:
storage: 20Gi
accessModes:
- ReadWriteMany
glusterfs:
endpoints: "glusterfs-cluster"
path: "mysql-volume"
readOnly: false
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wordpress-html-pvc
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 20Gi
selector:
matchLabels:
name: "html"
5.啟動上述檔案
[[email protected] yaml]# kubectl apply -f wordpress-pvc.yaml
persistentvolume "wordpress-html" configured
persistentvolumeclaim "wordpress-html-pvc" configured
6.檢視pv&pvc狀態
[[email protected] yaml]# kubectl get pv
NAME CAPACITY ACCESSMODES RECLAIMPOLICY STATUS CLAIM REASON AGE
gluster-dev-volume1 10Gi RWX Retain Bound default/glusterfs-mysql1 1d
wordpress-html 20Gi RWX Retain Bound default/wordpress-html-pvc 23h
wordpress-mysql 20Gi RWX Retain Bound default/wordpress-mysql-pvc 23h
[[email protected] yaml]# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESSMODES AGE
glusterfs-mysql1 Bound gluster-dev-volume1 10Gi RWX 1d
wordpress-html-pvc Bound wordpress-html 20Gi RWX 23h
wordpress-mysql-pvc Bound wordpress-mysql 20Gi RWX 23h
mysql配置
1.設定mysql 祕鑰[[email protected] yaml]# kubectl create secret generic mysql-pass --from-literal=password=root123456
檢視祕鑰
[[email protected] yaml]# kubectl get secret
NAME TYPE DATA AGE
mysql-pass Opaque 1 23h
2.編寫mysql yaml檔案如下,注意claimName為mysql pvc的名稱
[[email protected] yaml]# vi mysql-deployment-2.yaml
apiVersion: v1
kind: Service
metadata:
name: wordpress-mysql
labels:
app: wordpress
spec:
ports:
- port: 3306
selector:
app: wordpress
tier: mysql
clusterIP: None
---
apiVersion: extensions/v1beta1 # for versions before 1.8.0 use apps/v1beta1
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:
- image: docker.io/mysql
name: mysql
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-pass
key: password
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- name: mysql-persistent-storage
mountPath: /var/lib/mysql
volumes:
- name: mysql-persistent-storage
persistentVolumeClaim:
claimName: wordpress-mysql-pvc
3.建立mysql
[[email protected] yaml]# kubectl apply -f mysql-deployment-2.yaml
service "wordpress-mysql" configured
deployment "wordpress-mysql" configured
wordpress配置
1.編寫wordpress yaml檔案如下[[email protected] yaml]# vi wordpress-deployment.yaml
apiVersion: v1
kind: Service
metadata:
name: wordpress
labels:
app: wordpress
spec:
ports:
- port: 80
selector:
app: wordpress
tier: frontend
type: LoadBalancer
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: wordpress
labels:
app: wordpress
spec:
selector:
matchLabels:
app: wordpress
tier: frontend
strategy:
type: Recreate
template:
metadata:
labels:
app: wordpress
tier: frontend
spec:
containers:
- image: docker.io/wordpress
name: wordpress
env:
- name: WORDPRESS_DB_HOST
value: wordpress-mysql
- name: WORDPRESS_DB_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-pass
key: password
ports:
- containerPort: 80
name: wordpress
volumeMounts:
- name: wordpress-persistent-storage
mountPath: /var/www/html
volumes:
- name: wordpress-persistent-storage
persistentVolumeClaim:
claimName: wordpress-html-pvc
2.啟動wordpress
[[email protected] yaml]# kubectl apply -f wordpress-deployment.yaml
service "wordpress" configured
deployment "wordpress" configured
3.檢視mysql&wordpress狀態
[[email protected] yaml]# kubectl get deployment
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
wordpress 1 1 1 1 2h
wordpress-mysql 1 1 1 1 2h
[[email protected] yaml]# kubectl get services
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
glusterfs-cluster 172.17.62.135 <none> 1/TCP 1d
kubernetes 10.254.0.1 <none> 443/TCP 7d
redis-master 172.17.188.179 <none> 6379/TCP 1h
wordpress 172.17.110.149 <pending> 80:30503/TCP 2h
wordpress-mysql None <none> 3306/TCP 2h
[[email protected] yaml]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE
busybox 1/1 Running 1 1h 172.17.17.3 10.10.200.229
wordpress-2685813842-2pqw1 1/1 Running 0 2h 172.17.17.5 10.10.200.229
wordpress-mysql-3121681020-d35tb 1/1 Running 0 2h 172.17.17.4 10.10.200.229
4.訪問http://10.10.200.229:30503,就可以進入wordpress介面了