好物优选点击查看详情 京东购买

暂无内容

Docker容器与虚拟化技术

1、NFS依赖包安装(master及node节点)

 yum install nfs-utils -y systemctl enable nfs-server && systemctl start nfs-server

2、为Master下mysql data和wordpress源码配置NFS共享目录

mkdir -p /kube/mysql-db mkdir -p /kube/wordpress chown nfsnobody:nfsnobody /kube/mysql-db chown nfsnobody:nfsnobody /kube/wordpress chmod 755 /kube/mysql-db chmod 755 /kube/wordpress echo -e "/kube/mysql-db *(rw,sync,no_subtree_check,no_root_squash)" > /etc/exports echo -e "/kube/wordpress *(rw,sync,no_subtree_check,no_root_squash)" >> /etc/exports exportfs -a

3、编辑wordpress.yaml文件

apiVersion: v1 kind: PersistentVolume metadata: name: mysql-pv labels: app: mysql spec: capacity: storage: 5Gi accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Recycle nfs: path: /kube/mysql-db server: docker3 --- apiVersion: v1 kind: PersistentVolume metadata: name: wp-pv labels: app: wordpress spec: capacity: storage: 5Gi accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Recycle nfs: path: /kube/wordpress server: docker3 --- kind: PersistentVolumeClaim apiVersion: v1 metadata: name: mysql-pv-claim labels: app: mysql spec: accessModes: - ReadWriteOnce resources: requests: storage: 2Gi --- kind: PersistentVolumeClaim apiVersion: v1 metadata: name: wp-pv-claim labels: app: wordpress spec: accessModes: - ReadWriteOnce resources: requests: storage: 2Gi --- apiVersion: apps/v1 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: mysql:5.6 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: mysql-pv-claim --- apiVersion: apps/v1 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: wordpress:4.8-apache 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: wp-pv-claim --- apiVersion: v1 kind: Service metadata: name: wordpress-mysql labels: app: wordpress spec: ports: - port: 3306 selector: app: wordpress tier: mysql clusterIP: None --- apiVersion: v1 kind: Service metadata: name: wordpress labels: app: wordpress spec: ports: - port: 80 nodePort: 30080 selector: app: wordpress tier: frontend type: NodePort

4、部署:kubectl create -f wordpress.yaml

登录页面:http://192.168.11.157:30080

原文链接:https://blog.csdn.net/lkolkolkol/article/details/106366634

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享