K8S中使用glusterfs

環(huán)境信息

三臺機(jī)器,操作系統(tǒng)CentOS 7.4:
hanyu-210 10.20.0.210
hanyu-211 10.20.0.211
hanyu-212 10.20.0.212

前提條件:

已搭建K8S集群(1個master 2個node節(jié)點)

1犹撒、搭建glusterFS集群(除非特別說明逻卖,否則三個節(jié)點都執(zhí)行)

執(zhí)行

[root@hanyu-210 k8s_glusterfs]# yum install centos-release-gluster
[root@hanyu-210 k8s_glusterfs]# yum install -y glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma

配置 GlusterFS 集群

[root@hanyu-210 k8s_glusterfs]# systemctl start glusterd.service
[root@hanyu-210 k8s_glusterfs]# systemctl enable glusterd.service

hanyu-210節(jié)點執(zhí)行

[root@hanyu-210 k8s_glusterfs]# gluster peer probe hanyu-210
[root@hanyu-210 k8s_glusterfs]# gluster peer probe hanyu-211
[root@hanyu-210 k8s_glusterfs]# gluster peer probe hanyu-212

創(chuàng)建數(shù)據(jù)目錄

[root@hanyu-210 k8s_glusterfs]# mkdir -p /opt/gfs_data

創(chuàng)建復(fù)制卷

[root@hanyu-210 k8s_glusterfs]# gluster volume create k8s-volume replica 3 hanyu-210:/opt/gfs_data hanyu-211:/opt/gfs_data hanyu-212:/opt/gfs_data force

啟動卷

[root@hanyu-210 k8s_glusterfs]# gluster volume start k8s-volume

查詢卷狀態(tài)

[root@hanyu-210 k8s_glusterfs]# gluster volume status
Status of volume: k8s-volume
Gluster process                             TCP Port  RDMA Port  Online  Pid
------------------------------------------------------------------------------
Brick hanyu-210:/opt/gfs_data               49152     0          Y       29445
Brick hanyu-212:/opt/gfs_data               49152     0          Y       32098
Self-heal Daemon on localhost               N/A       N/A        Y       29466
Self-heal Daemon on hanyu-212               N/A       N/A        Y       32119

Task Status of Volume k8s-volume
------------------------------------------------------------------------------
There are no active volume tasks
[root@hanyu-210 k8s_glusterfs]# gluster volume info
Volume Name: k8s-volume
Type: Replicate
Volume ID: 7d7ecba3-7bc9-4e09-89ed-493b3a6a2454
Status: Started
Snapshot Count: 0
Number of Bricks: 1 x 3 = 3
Transport-type: tcp
Bricks:
Brick1: hanyu-210:/opt/gfs_data
Brick2: hanyu-211:/opt/gfs_data
Brick3: hanyu-212:/opt/gfs_data
Options Reconfigured:
transport.address-family: inet
nfs.disable: on
performance.client-io-threads: off

驗證glusterFS集群可用

選擇其中一臺主機(jī)執(zhí)行

yum install -y glusterfs glusterfs-fuse
mkdir -p /root/test
mount -t glusterfs hanyu-210:k8s-volume /root/test
df -h
umount /root/test

2递雀、使用glusterfs(以下均在k8s master節(jié)點執(zhí)行)

創(chuàng)建glusterfs的endpoints及對應(yīng)的service:kubectl apply -f glusterfs-cluster.yaml

[root@hanyu-210 k8s_glusterfs]# cat glusterfs-cluster.yaml
apiVersion: v1
kind: Endpoints
metadata:
  name: glusterfs-cluster
subsets:
- addresses:
  - ip: 10.20.0.210
  ports:
  - port: 49152
- addresses:
  - ip: 10.20.0.211
  ports:
  - port: 49152
- addresses:
  - ip: 10.20.0.212
  ports:
  - port: 49152
---
apiVersion: v1
kind: Service
metadata:
  name: glusterfs-cluster
spec:
  ports:
  - port: 49152

創(chuàng)建應(yīng)用直接使用glusterfs作為存儲卷:kubectl apply -f nginx_deployment_test.yaml

[root@hanyu-210 k8s_glusterfs]# cat nginx_deployment_test.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment-test
spec:
  replicas: 3
  selector:
    matchLabels:
      name: nginx
  template:
    metadata:
      labels:
        name: nginx
    spec:
      containers:
        - name: nginx
          image: nginx
          ports:
            - containerPort: 80
          volumeMounts:
            - name: storage001
              mountPath: "/usr/share/nginx/html"
      volumes:
      - name: storage001
        glusterfs:
          endpoints: glusterfs-cluster
          path: k8s-volume
          readOnly: false
1.png
2.png

創(chuàng)建pv使用glusterfs:kubectl apply -f glusterfs-pv.yaml

[root@hanyu-210 k8s_glusterfs]# cat glusterfs-pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: glusterfs-pv
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteMany
  glusterfs:
    endpoints: glusterfs-cluster
    path: k8s-volume
    readOnly: false

創(chuàng)建pvc聲明:kubectl apply -f glusterfs-pvc.yaml

[root@hanyu-210 k8s_glusterfs]# cat glusterfs-pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: glusterfs-pvc
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: 2Gi

創(chuàng)建應(yīng)用使用pvc:kubectl apply -f nginx_deployment.yaml

[root@hanyu-210 k8s_glusterfs]# cat nginx_deployment.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: storage001
              mountPath: "/usr/share/nginx/html"
      volumes:
      - name: storage001
        persistentVolumeClaim:
          claimName: glusterfs-pvc
3.png
4.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子秆乳,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,542評論 6 504
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件屹堰,死亡現(xiàn)場離奇詭異肛冶,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)扯键,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,822評論 3 394
  • 文/潘曉璐 我一進(jìn)店門睦袖,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人荣刑,你說我怎么就攤上這事馅笙。” “怎么了厉亏?”我有些...
    開封第一講書人閱讀 163,912評論 0 354
  • 文/不壞的土叔 我叫張陵董习,是天一觀的道長。 經(jīng)常有香客問我爱只,道長皿淋,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,449評論 1 293
  • 正文 為了忘掉前任恬试,我火速辦了婚禮窝趣,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘训柴。我一直安慰自己高帖,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,500評論 6 392
  • 文/花漫 我一把揭開白布畦粮。 她就那樣靜靜地躺著散址,像睡著了一般。 火紅的嫁衣襯著肌膚如雪宣赔。 梳的紋絲不亂的頭發(fā)上预麸,一...
    開封第一講書人閱讀 51,370評論 1 302
  • 那天,我揣著相機(jī)與錄音儒将,去河邊找鬼吏祸。 笑死,一個胖子當(dāng)著我的面吹牛钩蚊,可吹牛的內(nèi)容都是我干的贡翘。 我是一名探鬼主播,決...
    沈念sama閱讀 40,193評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼砰逻,長吁一口氣:“原來是場噩夢啊……” “哼鸣驱!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起蝠咆,我...
    開封第一講書人閱讀 39,074評論 0 276
  • 序言:老撾萬榮一對情侶失蹤踊东,失蹤者是張志新(化名)和其女友劉穎北滥,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體闸翅,經(jīng)...
    沈念sama閱讀 45,505評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡再芋,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,722評論 3 335
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了坚冀。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片济赎。...
    茶點故事閱讀 39,841評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖记某,靈堂內(nèi)的尸體忽然破棺而出联喘,到底是詐尸還是另有隱情,我是刑警寧澤辙纬,帶...
    沈念sama閱讀 35,569評論 5 345
  • 正文 年R本政府宣布,位于F島的核電站叭喜,受9級特大地震影響贺拣,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜捂蕴,卻給世界環(huán)境...
    茶點故事閱讀 41,168評論 3 328
  • 文/蒙蒙 一譬涡、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧啥辨,春花似錦涡匀、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,783評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至级乍,卻和暖如春舌劳,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背玫荣。 一陣腳步聲響...
    開封第一講書人閱讀 32,918評論 1 269
  • 我被黑心中介騙來泰國打工甚淡, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人捅厂。 一個月前我還...
    沈念sama閱讀 47,962評論 2 370
  • 正文 我出身青樓贯卦,卻偏偏與公主長得像,于是被迫代替她去往敵國和親焙贷。 傳聞我的和親對象是個殘疾皇子撵割,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,781評論 2 354