上传镜像到harbor

docker pull mysql:5.7
docker pull richarvey/nginx-php-fpm
docker tag docker.io/richarvey/nginx-php-fpm hqq365.com:8443/lmnp/nginx-php-fpm:latest
docker tag docker.io/mysql:5.7 hqq365.com:8443/lmnp/mysql:5.7
docker push hqq365.com:8443/lmnp/nginx-php-fpm:latest
docker push hqq365.com:8443/lmnp/mysql:5.7

部署NFS
[root@master2 ~]# mkdir -p /data/k8s/{web,db}
[root@master2 ~]# yum -y install nfs-utils
[root@master2 ~]# vim /etc/exports
/data/k8s 192.168.1.0/24(sync,rw,no_root_squash)
systemctl restart nfs
systemctl enable nfs
部署mysql
mkdir -p /home/k8s/lnmp/mysql
创建secret,将mysql数据库的密码存放到secret中
[root@master mysql]# kubectl create secret generic mysql-pass --from-literal=password=123456
1、创建mysql-pv

apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-pv
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteMany
  nfs:
    path: /data/k8s/db              ##该参数指定你的NFS端的共享目录
    server: 192.168.222.145           ##指定nfs端的IP

kubectl create -f mysql-pv.yaml

2、创建mysql-pvc

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

kubectl create -f mysql-pvc.yaml

3、创建mysql-deploy
vim mysql-dp.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: dz-mysql
  labels:
    app: discuz
spec:
  selector:
    matchLabels:
      app: discuz
      tier: mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: discuz
        tier: mysql
    spec:
      imagePullSecrets:
       - name: my-secret
      containers:
      - image: hqq365.com:8443/lmnp/mysql:5.7      ##此处指定你的harbor需要拉取的镜像
        name: mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysql-pass                    ##此模块是调用secret中存放的mysql密码
              key: password
        ports:
        - containerPort: 3306
          name: dz-mysql
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:                     ##此模块参数调用定义创建的pvc名称
          claimName: mysql-claim

kubectl create -f mysql-dp.yaml

4、创建mysql-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、查看pod svc状态
kubectl get pod,svc

安装Nginx服务

1:创建nginx-pv
vim web-pv.yaml

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

2:创建nginx-pvc
vim web-pvc.yaml

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

3、创建nginx-deploy
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:
      imagePullSecrets:
      - name: my-secret
      containers:
      - image: hqq365.com:8443/lmnp/nginx-php-fpm:latest
        name: dz-web
        ports:
        - containerPort: 9000
        - containerPort: 80
          name: dz-web
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/www/html/
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: web-claim

4、创建nginx-service

映射端口30001提供集群外部的机器访问web网站

vim web-svc.yaml

apiVersion: v1
kind: Service
metadata:
  name: dz-web
  labels:
    app: discuz
spec:
  type: NodePort
  ports:
    - port: 80
      nodePort: 30001
  selector:
    app: discuz
    tier: nginx-php

5、查看po svc状态
kubectl get po,svc

安装Discuz

标签: none

添加新评论