码迷,mamicode.com
首页 > Web开发 > 详细

在kubernetes集群中搭建LNMP并运行discuz

时间:2018-09-20 13:11:13      阅读:1038      评论:0      收藏:0      [点我收藏+]

标签:ice   nfs-utils   Kubernete   yaml   star   https   rbo   emctl   http   

文档整理 https://coding.net/u/aminglinux/p/k8s_discuz/git/tree/master

1 下载MySQL、PHP以及Nginx镜像

docker pull mysql:5.7
docker pull richarvey/nginx-php-fpm

2 将下载到的镜像push到harbor

docker tag mysql:5.7 harbor.yuankeedu.com/aminglinux/mysql:5.7
docker push harbor.yuankeedu.com/aminglinux/mysql:5.7
docker tag aming-nginx-php harbor.yuankeedu.com/aminglinux/nginx-php
docker push harbor.yuankeedu.com/aminglinux/nginx-php

3 搭建NFS服务

yum install nfs-utils
vim /etc/exportfs
/data/k8s/ 172.7.5.0/24(sync,rw,no_root_squash)
systemctl start nfs
systemctl enable nfs

mkdir -p  /data/k8s/discuz/{db,web}

4 搭建MySQL服务
1)创建secret
kubectl create secret generic mysql-pass --from-literal=password=DzPasswd123

2)创建pv

vim mysql-pv.yaml  //内容如下

apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-pv
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteMany
  nfs:
    path: /data/k8s/discuz/db
    server: 172.7.5.113

kubectl create -f mysql-pv.yaml

3)创建pvc

vim  mysql-pvc.yaml //内容如下

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-claim
  labels:
    app: discuz
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 10Gi

kubectl create -f mysql-pvc.yaml

4)创建deployment

vim mysql-dp.yaml  //内容如下

apiVersion: apps/v1
kind: Deployment
metadata:
  name: dz-mysql
  labels:
    app: discuz
spec:
  replicas: 2
  selector:
    matchLabels:
      app: discuz
      tier: mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: discuz
        tier: mysql
    spec:
      containers:
      - image: harbor.yuankeedu.com/aminglinux/mysql:5.7
    imagePullSecrets:
      - name: my-secret 
        name: dz-mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysql-pass
              key: password
        ports:
        - containerPort: 3306
          name: dz-mysql
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: mysql-claim

kubectl create -f mysql-dp.yaml 

5)创建service

vim mysql-svc.yaml

apiVersion: v1
kind: Service
metadata:
  name: dz-mysql
  labels:
    app: discuz
spec:
  ports:
    - port: 3306
  selector:
    app: discuz
    tier: mysql

kubectl create -f mysql-svc.yaml

5 搭建nginx+php-fpm服务
1)创建pv

vim web-pv.yaml  //内容如下

apiVersion: v1
kind: PersistentVolume
metadata:
  name: web-pv
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteMany
  nfs:
    path: /data/k8s/discuz/web
    server: 172.7.5.113

kubectl create -f web-pv.yaml

2)创建pvc

vim  web-pvc.yaml //内容如下

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: web-claim
  labels:
    app: discuz
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 10Gi

kubectl create -f web-pvc.yaml

3)创建deployment

vim web-dp.yaml  //内容如下

apiVersion: apps/v1
kind: Deployment
metadata:
  name: dz-web
  labels:
    app: discuz
spec:
  replicas: 1
  selector:
    matchLabels:
      app: discuz
      tier: nginx-php
  template:
    metadata:
      labels:
        app: discuz
        tier: nginx-php
    spec:
      containers:
      - image: harbor.yuankeedu.com/aminglinux/nginx-php
        name: dz-web
        ports:
        - containerPort: 9000
        - containerPort: 80
          name: dz-web
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/www/html/
      imagePullSecrets:
      - name: my-secret
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: web-claim

kubectl create -f web-dp.yaml 

4)创建service

vim web-svc.yaml

apiVersion: v1
kind: Service
metadata:
  name: dz-web
  labels:
    app: discuz
spec:
  ports:
    - port: 9000
  selector:
    app: discuz
    tier: nginx-php

kubectl create -f web-svc.yaml

在kubernetes集群中搭建LNMP并运行discuz

标签:ice   nfs-utils   Kubernete   yaml   star   https   rbo   emctl   http   

原文地址:http://blog.51cto.com/aminglinux/2177558

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!