1 部署NFS服务 做共享存储
服务端:172.18.47.93
yum install nfs-utils -y
编辑配置文件
[root@localhost ~]# vim /etc/exports /nfs 172.18.47.0/16(rw,no_root_squash)
开启服务
[root@localhost ~]# systemctl enable nfs [root@localhost ~]# systemctl start nfs
创建两个目录
[root@localhost nfs]# mkdir {mysql,nginx}
[root@localhost nfs]# ll
总用量 0
drwxr-xr-x. 2 root root 6 1月 7 15:18 mysql
drwxr-xr-x. 2 root root 6 1月 7 15:18 nginx
客户端:172.18.47.90/91/92
yum install nfs-utils -y
验证是否可以访问nfs服务端
[root@k8s-node1 ~]# showmount -e 172.18.47.93 Export list for 172.18.47.93: /nfs 172.18.47.0/16
2 创建pv
cat pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: mysql-pv
spec:
capacity:
storage: 20Gi
accessModes:
- ReadWriteMany
nfs:
path: /nfs/mysql
server: 172.18.47.93
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: wp-pv01
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteMany
nfs:
path: /nfs/nginx
server: 172.18.47.93
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: wp-pv02
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteMany
nfs:
path: /nfs/nginx
server: 172.18.47.93
[root@k8s-master pv]# kubectl apply -f pv.yaml persistentvolume/mysql-pv created persistentvolume/wp-pv01 created persistentvolume/wp-pv02 created
3 部署mysql
创建mysql-deployment
cat mysql-deployment.yaml
apiVersion: v1
kind: Service
metadata:
name: wordpress-mysql
labels:
app: wordpress
spec:
ports:
- port: 3306
selector:
app: wordpress
tier: mysql
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pv-claim
labels:
app: wordpress
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 20Gi
---
apiVersion: apps/v1beta2
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:
- name: mysql
spec:
containers:
- name: mysql
image: mysql:5.6
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-pass
key: password
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- mountPath: "/var/lib/mysql"
name: mysql-data
volumes:
- name: mysql-data
persistentVolumeClaim:
claimName: mysql-pv-claim
创建mysql容器
[root@k8s-master mysql]# kubectl apply -f mysql-deploy.yaml service/wordpress-mysql created persistentvolumeclaim/mysql-pv-claim created deployment.apps/wordpress-mysql created
通过secret 创建mysql 秘密
[root@k8s-master ~]# kubectl create secret generic mysql-pass --from-literal=password=123456 secret/mysql-pass created
4 上传镜像到harbor