Kubernetes-glusterfs配置

############################################
#pvc與pv的區別
#pv能夠看作一塊硬盤,pv能夠有不少塊不一樣大小的硬盤,好比有10G,50G,100G的3個PV
#pvc向pv申請40G的,那麼就會匹配到50G這個pv,那麼實際大小pvc有50G而不是原來限定的40G
#全部節點
#glusterfs
#http://www.cnblogs.com/jicki/p/5801712.html
#https://jimmysong.io/blogs/kubernetes-with-glusterfs/
yum install centos-release-gluster
yum install -y glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma
# 建立 glusterfs 目錄
mkdir /data/glusterd
sed -i 's#var/lib#dara#g' /etc/glusterfs/glusterd.vol
# 啓動 glusterfs
systemctl start glusterd.service
# 設置開機啓動
systemctl enable glusterd.service
#查看狀態
systemctl status glusterd.service
#開放端口,只對節點IP開放
for i in 192.168.1.1,192.168.1.2,192.168.1.3
do
    iptables -I INPUT -s $i  -p tcp -m multiport --dport 24007,49152 -j ACCEPT
done

#建立存儲目錄
mkdir /data/gfs_data
#添加節點,在master主機上執行
gluster peer probe minion-1
gluster peer probe minion-2
#查看狀態
gluster peer status
#容許全部
#gluster volume reset disp_vol auth.allow
#限制IP
gluster volume set disp_vol auth.allow 192.168.1.1,192.168.1.2,192.168.1.3
#建立複製卷,副本數爲3
gluster volume create test-volume replica 3 transport tcp master:/data/gfs_data minion-1:/data/gfs_data minion-2:/data/gfs_data
#調優,緩存過大可能忽然重啓斷電等狀況致使數據丟失
#啓動卷
gluster volume start test-volume
#查看卷狀態
gluster volume info
#設置配額
gluster volume quota test-volume enable
gluster volume quota test-volume limit-usage / 300GB
#設置緩存
gluster volume set test-volume performance.cache-size 2GB
#設置io線程
gluster volume set test-volume performance.io-thread-count 16
#設置網絡檢測時間
gluster volume set test-volume network.ping-timeout 10
#設置寫緩衝大小
gluster volume set test-volume performance.write-behind-window-size 512MB
#修改addresses ip每個一組,port改成24007
#kubectl apply更新
#配置glusterfs節點ip和端口
kubectl apply -f ./kubernetes/examples/volumes/glusterfs/glusterfs-endpoints.json
#配置集羣端口
kubectl apply -f ./kubernetes/examples/volumes/glusterfs/glusterfs-service.json
#kubectl apply -f demo.yum,添加了下面兩段,掛載到/data目錄,安裝好demo.yaml後可df -h查看data目錄是否掛載了300G
#在yaml的containers裏添加
"volumes": [
            "volumeMounts": [
                {
                    "mountPath": "/data",
                    "name": "glusterfdata"
                }
            ]
          }
#在yaml的containers下面添加
"volumes": [
            {
                "name": "glusterfdata",
                "glusterfs": {
                    "endpoints": "glusterfs-cluster",
                    "path": "test-volume",
                    "readOnly": false
                }
            }
        ],
#也可直接掛載的物理主機
mount.glusterfs 192.168.1.1:/test-volume /data/mnt
#建立pv
cat << EOF > glusterfs-pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: gluster-disk-1
spec:
  capacity:
    storage: 300Gi
  accessModes:
    - ReadWriteMany
  glusterfs:
    endpoints: "glusterfs-cluster"
    path: "test-volume"
    readOnly: false
EOF
kubectl apply -f glusterfs-pv.yaml
kubectl get pv
#建立PVC
cat << EOF>glusterfs-pvc.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: glusterfs-disk-1
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 300Gi
EOF
kubectl apply -f glusterfs-pvc.yaml
kubectl get pvc
kubect apply demo.yamlhtml

相關文章
相關標籤/搜索