Centos7通过Kubernetes+GlusterFS部署wordpress+mysql

操作环境

网络拓扑图



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

操作步骤

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


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    <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
[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界面了

























  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值