文檔整理 https://coding.net/u/aminglinux/p/k8s_discuz/git/tree/masterphp
1 下載MySQL、PHP以及Nginx鏡像html
docker pull mysql:5.7 docker pull richarvey/nginx-php-fpm
2 將下載到的鏡像push到harbormysql
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服務linux
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)建立secretkubectl create secret generic mysql-pass --from-literal=password=DzPasswd123
nginx
2)建立pvgit
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)建立pvcweb
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)建立deploymentsql
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)建立servicedocker
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)建立pvvim
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