1、GlusterFS 部署过程请参考上篇文章
2、配置endpoints
[root@manager ~]# cat glusterfs-endpoints.json { "kind": "Endpoints", "apiVersion": "v1", "metadata": { "name": "glusterfs-cluster" }, "subsets": [ { "addresses": [ { "ip": "192.168.10.223" } ], "ports": [ { "port": 1 } ] }, { "addresses": [ { "ip": "192.168.10.224" } ], "ports": [ { "port": 1 } ] }, { "addresses": [ { "ip": "192.168.10.225" } ], "ports": [ { "port": 1 } ] } ] }
[root@manager ~]# kubectl create -f glusterfs-endpoints.json
endpoints "glusterfs-cluster" created
[root@manager ~]#
[root@manager ~]# kubectl get ep
NAME ENDPOINTS AGE
glusterfs-cluster 192.168.10.223:1,192.168.10.224:1,192.168.10.225:1 6s
kubernetes 192.168.10.220:6443 5d
3、创建service
[root@manager ~]# cat glusterfs-service.yaml { "kind": "Service", "apiVersion": "v1", "metadata": { "name": "glusterfs-cluster" }, "spec": { "ports": [ {"port": 1} ] } } [root@manager ~]# [root@manager ~]# [root@manager ~]# kubectl create -f glusterfs-service.yaml service "glusterfs-cluster" created [root@manager ~]# [root@manager ~]# kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE glusterfs-cluster ClusterIP 10.10.10.194 <none> 1/TCP 7s kubernetes ClusterIP 10.10.10.1 <none> 443/TCP 5d
4、创建测试pod
[root@manager ~]# cat glusterfs-pod.yaml apiVersion: extensions/v1beta1 kind: Deployment metadata: name: nginx-deployment spec: replicas: 3 template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx volumeMounts: - name: glusterfsvol mountPath: /usr/share/nginx/html ports: - containerPort: 80 volumes: - name: glusterfsvol glusterfs: endpoints: glusterfs-cluster path: gv0 readOnly: false --- apiVersion: v1 kind: Service metadata: name: nginx-service spec: selector: app: nginx ports: - name: http port: 80 protocol: TCP targetPort: 80 type: NodePort
[root@manager ~]# kubectl create -f glusterfs-pod.yaml
deployment "nginx-deployment" created
service "nginx-service" created
[root@manager ~]# kubectl describe pod nginx-deployment-6f6f9646c4-84bbr
Name: nginx-deployment-6f6f9646c4-84bbr
Namespace: default
Node: 192.168.10.221/192.168.10.221
Start Time: Mon, 05 Feb 2018 14:31:54 +0800
Labels: app=nginx
pod-template-hash=2929520270
Annotations: kubernetes.io/created-by={"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"ReplicaSet","namespace":"default","name":"nginx-deployment-6f6f9646c4","uid":"41758808-0a3e-11e8-af8c-5254...
Status: Running
IP: 10.0.91.5
Created By: ReplicaSet/nginx-deployment-6f6f9646c4
Controlled By: ReplicaSet/nginx-deployment-6f6f9646c4
Containers:
nginx:
Container ID: docker://d7714c067d2c1ac115336715eb66235ee9153632eab2019c174b0384c0b04e8f
Image: nginx
Image ID: docker-pullable://nginx@sha256:285b49d42c703fdf257d1e2422765c4ba9d3e37768d6ea83d7fe2043dad6e63d
Port: 80/TCP
State: Running
Started: Mon, 05 Feb 2018 14:32:34 +0800
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/usr/share/nginx/html from glusterfsvol (rw)
Conditions:
Type Status
Initialized True
Ready True
PodScheduled True
Volumes:
glusterfsvol:
Type: Glusterfs (a Glusterfs mount on the host that shares a pod's lifetime)
EndpointsName: glusterfs-cluster
Path: gv0
ReadOnly: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: <none>
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 42s default-scheduler Successfully assigned nginx-deployment-6f6f9646c4-84bbr to 192.168.10.221
Normal SuccessfulMountVolume 41s kubelet, 192.168.10.221 MountVolume.SetUp succeeded for volume "glusterfsvol"
Normal Pulling 40s kubelet, 192.168.10.221 pulling image "nginx"
Normal Pulled 2s kubelet, 192.168.10.221 Successfully pulled image "nginx"
Normal Created 2s kubelet, 192.168.10.221 Created container
Normal Started 2s kubelet, 192.168.10.221 Started container
[root@manager ~]# kubectl exec nginx-deployment-6f6f9646c4-84bbr mount|grep gluster
192.168.10.223:gv0 on /usr/share/nginx/html type fuse.glusterfs (rw,relatime,user_id=0,group_id=0,default_permissions,allow_other,max_read=131072)
root@nginx-deployment-6f6f9646c4-84bbr:/usr/share/nginx/html# echo abc > 2.txt
[root@glusterfs1 brick1]# cat 2.txt
abc
[root@glusterfs1 brick1]# echo 33333 > 3.txt
5、注意事项:
5.1、k8s集群配置glusterfs集群主机名接卸
5.2、k8s集群配置glusterfs 客户端挂载工具
[root@node1 ~]# yum install centos-release-gluster -y
[root@node1 ~]# yum install glusterfs-fuse -y