Centos7通过Kubernetes+GlusterFS部署wordpress+mysql

操作环境

网络拓扑图

Centos7通过Kubernetes+GlusterFS部署wordpress+mysql_第1张图片

OS
CentOS Linux release 7.4.1708 (Core) 
docker
Client:
 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
Kubernetes v1.5.2
glusterfs

glusterfs 3.12.3

操作步骤

     这里的配置步骤都是基于前几篇文章来的,就不详细说明了

      《 Centos7 下Kubernetes集群安装部署》
      《Centos7 下Kubernetes配置flannel网络》
      《Centos7下Kubernetes配置使用GlusterFS》
      《Centos7下Kubernetes配置DNS》

PV&PVC配置

1.编写mysql pv yaml文件如下:

[root@k8s-master 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
2.编写mysql pvc yaml文件如下:

[root@k8s-master 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 文件

[root@k8s-master yaml]# kubectl apply -f glusterfs-pv.yaml 
persistentvolume "wordpress-mysql" configured
[root@k8s-master yaml]# kubectl apply -f glusterfs-pvc.yaml 
persistentvolumeclaim "wordpress-mysql-pvc" configured
4.编写wordpress pv & pvc yaml配置文件,这里将2个写在一起

[root@k8s-master 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.启动上述文件

[root@k8s-master yaml]# kubectl apply -f wordpress-pvc.yaml 
persistentvolume "wordpress-html" configured
persistentvolumeclaim "wordpress-html-pvc" configured
6.查看pv&pvc状态

[root@k8s-master 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
[root@k8s-master 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 秘钥

[root@k8s-master yaml]# kubectl create secret generic mysql-pass --from-literal=password=root123456
查看秘钥

[root@k8s-master yaml]# kubectl get secret 
NAME         TYPE      DATA      AGE
mysql-pass   Opaque    1         23h
2.编写mysql yaml文件如下,注意claimName为mysql pvc的名称

[root@k8s-master 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

[root@k8s-master yaml]# kubectl apply -f mysql-deployment-2.yaml 
service "wordpress-mysql" configured
deployment "wordpress-mysql" configured

wordpress配置

1.编写wordpress yaml文件如下

[root@k8s-master 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

[root@k8s-master yaml]# kubectl apply -f wordpress-deployment.yaml 
service "wordpress" configured
deployment "wordpress" configured
3.查看mysql&wordpress状态

[root@k8s-master 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
[root@k8s-master yaml]# kubectl get services
NAME                CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
glusterfs-cluster   172.17.62.135            1/TCP          1d
kubernetes          10.254.0.1               443/TCP        7d
redis-master        172.17.188.179           6379/TCP       1h
wordpress           172.17.110.149        80:30503/TCP   2h
wordpress-mysql     None                     3306/TCP       2h
[root@k8s-master 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界面了

Centos7通过Kubernetes+GlusterFS部署wordpress+mysql_第2张图片























你可能感兴趣的:(docker,Kubernetes)