安装过程参照上一节。
[root@k8s-n1 ~]# mkdir glusterfs
[root@k8s-n1 ~]# cd glusterfs/
[root@k8s-n1 glusterfs]# cat glusterfs-endpoints.json
{
"kind": "Endpoints",
"apiVersion": "v1",
"metadata": {
"name": "glusterfs-cluster"
},
"subsets": [
{
"addresses": [{ "ip": "192.168.0.125" }],
"ports": [{ "port": 1990 }]
},
{
"addresses": [{ "ip": "192.168.0.126" }],
"ports": [{ "port": 1990 }]
},
{
"addresses": [{ "ip": "192.168.0.127" }],
"ports": [{ "port": 1990 }]
},
{
"addresses": [{ "ip": "192.168.0.128" }],
"ports": [{ "port": 1990 }]
}
]
}
[root@k8s-n1 glusterfs]# cat glusterfs-service.json
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": "glusterfs-cluster"
},
"spec": {
"ports": [
{"port": 1990}
]
}
}
kubectl apply -f glusterfs-endpoints.json
kubectl apply -f glusterfs-service.json
[root@k8s-n1 glusterfs]# cat glusterfs-pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: gluster-dev-volume
spec:
capacity:
storage: 8Gi
accessModes:
- ReadWriteMany
glusterfs:
endpoints: "glusterfs-cluster"
path: "gv0"
readOnly: false
[root@k8s-n1 glusterfs]# cat glusterfs-pvc.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: glusterfs-nginx
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 8Gi
[root@k8s-n1 glusterfs]# kubectl apply -f glusterfs-pv.yaml
[root@k8s-n1 glusterfs]# kubectl apply -f glusterfs-pvc.yaml
[root@k8s-n1 glusterfs]# cat nginx_deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
selector:
matchLabels:
name: nginx
template:
metadata:
labels:
name: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
volumeMounts:
- name: storage002
mountPath: "/usr/share/nginx/html"
volumes:
- name: storage002
persistentVolumeClaim:
claimName: glusterfs-nginx
[root@k8s-n1 glusterfs]# kubectl apply -f nginx_deploy.yaml
[root@k8s-n1 glusterfs]# kubectl get pod -o wide | grep nginx
nginx-deployment-5676b98589-2g6v5 1/1 Running 0 10h 10.100.57.194 k8s-n3 <none> <none>
nginx-deployment-5676b98589-t8j2r 1/1 Running 0 10h 10.100.111.196 k8s-n2 <none> <none>
nginx-deployment-5676b98589-x7bsv 1/1 Running 0 10h 10.100.118.2 k8s-n4 <none> <none>
#查看共享存储情况
[root@k8s-n1 glusterfs]# kubectl exec -it nginx-deployment-5676b98589-t8j2r /bin/sh
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl kubectl exec [POD] -- [COMMAND] instead.
# ls /usr/share/nginx/html
testsss