Kubernetes 使用 NFS PVC

存儲端配置

多個存儲節(jié)點使用 DRBD & Pacemaker 配置高可用 nfs 服務

軟件安裝

apt install -y nfs-kernel-server pacemaker crmsh corosync ntpdate

DRBD 相關安裝

服務配置

同步時間

ntpdate -u ntp.api.bz

創(chuàng)建 DRBD 卷

創(chuàng)建 Corosync 集群

配置 /etc/corosync/corosync.conf 文件,內容如下
注意 bindnetaddr 與 nodelist 的地址

root@km99:~# cat /etc/corosync/corosync.conf
# Please read the corosync.conf.5 manual page
totem {
        version: 2

        # Corosync itself works without a cluster name, but DLM needs one.
        # The cluster name is also written into the VG metadata of newly
        # created shared LVM volume groups, if lvmlockd uses DLM locking.
        # It is also used for computing mcastaddr, unless overridden below.
        cluster_name: k8snfsserver

        # How long before declaring a token lost (ms)
        token: 3000

        # How many token retransmits before forming a new configuration
        token_retransmits_before_loss_const: 10

        # Limit generated nodeids to 31-bits (positive signed integers)
        clear_node_high_bit: yes

        # crypto_cipher and crypto_hash: Used for mutual node authentication.
        # If you choose to enable this, then do remember to create a shared
        # secret with "corosync-keygen".
        # enabling crypto_cipher, requires also enabling of crypto_hash.
        # crypto_cipher and crypto_hash should be used instead of deprecated
        # secauth parameter.

        # Valid values for crypto_cipher are none (no encryption), aes256, aes192,
        # aes128 and  3des. Enabling crypto_cipher, requires also enabling of
        # crypto_hash.
        crypto_cipher: none

        # Valid values for crypto_hash are  none  (no  authentication),  md5,  sha1,
        # sha256, sha384 and sha512.
        crypto_hash: none

        # Optionally assign a fixed node id (integer)
        # nodeid: 1234

        # interface: define at least one interface to communicate
        # over. If you define more than one interface stanza, you must
        # also set rrp_mode.
        interface {
                # Rings must be consecutively numbered, starting at 0.
                ringnumber: 0
                # This is normally the *network* address of the
                # interface to bind to. This ensures that you can use
                # identical instances of this configuration file
                # across all your cluster nodes, without having to
                # modify this option.
                bindnetaddr: 10.203.1.0
                # However, if you have multiple physical network
                # interfaces configured for the same subnet, then the
                # network address alone is not sufficient to identify
                # the interface Corosync should bind to. In that case,
                # configure the *host* address of the interface
                # instead:
                # bindnetaddr: 192.168.1.1
                # When selecting a multicast address, consider RFC
                # 2365 (which, among other things, specifies that
                # 239.255.x.x addresses are left to the discretion of
                # the network administrator). Do not reuse multicast
                # addresses across multiple Corosync clusters sharing
                # the same network.
                # mcastaddr: 239.255.1.1
                # Corosync uses the port you specify here for UDP
                # messaging, and also the immediately preceding
                # port. Thus if you set this to 5405, Corosync sends
                # messages over UDP ports 5405 and 5404.
                mcastport: 5405
                # Time-to-live for cluster communication packets. The
                # number of hops (routers) that this ring will allow
                # itself to pass. Note that multicast routing must be
                # specifically enabled on most network routers.
                ttl: 1
        }
}
nodelist { 
   node {
      ring0_addr: 10.203.1.99
      name: km99
   } 
   node {
      ring0_addr: 10.203.1.101
      name: ubuntu
   }  
}
logging {
        # Log the source file and line where messages are being
        # generated. When in doubt, leave off. Potentially useful for
        # debugging.
        fileline: off
        # Log to standard error. When in doubt, set to no. Useful when
        # running in the foreground (when invoking "corosync -f")
        to_stderr: no
        # Log to a log file. When set to "no", the "logfile" option
        # must not be set.
        to_logfile: no
        #logfile: /var/log/corosync/corosync.log
        # Log to the system log daemon. When in doubt, set to yes.
        to_syslog: yes
        # Log with syslog facility daemon.
        syslog_facility: daemon
        # Log debug messages (very verbose). When in doubt, leave off.
        debug: off
        # Log messages with time stamps. When in doubt, set to on
        # (unless you are only logging to syslog, where double
        # timestamps can be annoying).
        timestamp: on
        logger_subsys {
                subsys: QUORUM
                debug: off
        }
}

quorum {
        # Enable and configure quorum subsystem (default: off)
        # see also corosync.conf.5 and votequorum.5
        provider: corosync_votequorum
        expected_votes: 2
}

重啟服務

systemctl restart corosync

查看心跳線狀態(tài)

corosync-cfgtool -s

NFS service 配置

使用 crm cof edit 命令打開編輯幻锁,配置信息如下

primitive nfs IPaddr \
        params ip=10.203.1.87
primitive nfs_start systemd:nfs-server \
        op start timeout=100 interval=0 \
        op stop timeout=100 interval=0
primitive nfsserver Filesystem \
        params device="/dev/drbd1002" directory="/home/share/minionfs" fstype=ext4 \
        op start timeout=60 interval=0 \
        op stop timeout=60 interval=0
location cli-prefer-nfs nfs role=Started inf: km99
colocation nfs_start_with_nfsserver inf: nfs_start nfsserver
order server_befor_start Mandatory: nfsserver nfs_start
colocation vip_with_nfs inf: nfs nfs_start

應用端配置

軟件安裝

apt install nfs-common

pv & pvc

root@km99:~/k8syaml/nfs# cat minionfspv.yaml 
apiVersion: v1
kind: PersistentVolume
metadata:
  name: minionfspv
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  storageClassName: nfs
  nfs:
    path: /home/share/minionfs
    server: 10.203.1.87
root@km99:~/k8syaml/nfs# cat minionfspvc.yaml 
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: minionfspvc
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 10Gi
  storageClassName: nfs

Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: minionfs-ha
spec:
  replicas: 2
  strategy:
    type: RollingUpdate
  selector:
    matchLabels:
      app: minionfsha
  template:
    metadata:
      labels:
        app: minionfsha
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: lst
                operator: In
                values:
                - yyyyy
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - minionfsha
            topologyKey: kubernetes.io/hostname
      containers:
      - name: minionfsha
        image: minio/minio:RELEASE.2020-12-03T00-03-10Z
        #args:
        #- server
        #- /data
        command:
          - /bin/sh
          - '-ce'
          - /usr/bin/docker-entrypoint.sh minio -C /root/.minio/ server /data 
        ports:
        - containerPort: 9000
          protocol: TCP
        volumeMounts:
        - name: minio-volume
          mountPath: /data
      volumes:
      - name: minio-volume
        persistentVolumeClaim:
          claimName: minionfspvc
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末矢棚,一起剝皮案震驚了整個濱河市宗挥,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌霞捡,老刑警劉巖耐朴,帶你破解...
    沈念sama閱讀 217,734評論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異泄隔,居然都是意外死亡,警方通過查閱死者的電腦和手機宛徊,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,931評論 3 394
  • 文/潘曉璐 我一進店門佛嬉,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人闸天,你說我怎么就攤上這事暖呕。” “怎么了苞氮?”我有些...
    開封第一講書人閱讀 164,133評論 0 354
  • 文/不壞的土叔 我叫張陵湾揽,是天一觀的道長。 經(jīng)常有香客問我笼吟,道長钝腺,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,532評論 1 293
  • 正文 為了忘掉前任赞厕,我火速辦了婚禮,結果婚禮上定硝,老公的妹妹穿的比我還像新娘皿桑。我一直安慰自己,他們只是感情好蔬啡,可當我...
    茶點故事閱讀 67,585評論 6 392
  • 文/花漫 我一把揭開白布诲侮。 她就那樣靜靜地躺著,像睡著了一般箱蟆。 火紅的嫁衣襯著肌膚如雪沟绪。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,462評論 1 302
  • 那天空猜,我揣著相機與錄音绽慈,去河邊找鬼。 笑死辈毯,一個胖子當著我的面吹牛坝疼,可吹牛的內容都是我干的。 我是一名探鬼主播谆沃,決...
    沈念sama閱讀 40,262評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼钝凶,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了唁影?” 一聲冷哼從身側響起耕陷,我...
    開封第一講書人閱讀 39,153評論 0 276
  • 序言:老撾萬榮一對情侶失蹤掂名,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后哟沫,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體饺蔑,經(jīng)...
    沈念sama閱讀 45,587評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,792評論 3 336
  • 正文 我和宋清朗相戀三年南用,在試婚紗的時候發(fā)現(xiàn)自己被綠了膀钠。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,919評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡裹虫,死狀恐怖肿嘲,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情筑公,我是刑警寧澤雳窟,帶...
    沈念sama閱讀 35,635評論 5 345
  • 正文 年R本政府宣布,位于F島的核電站匣屡,受9級特大地震影響封救,放射性物質發(fā)生泄漏。R本人自食惡果不足惜捣作,卻給世界環(huán)境...
    茶點故事閱讀 41,237評論 3 329
  • 文/蒙蒙 一誉结、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧券躁,春花似錦惩坑、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,855評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至慢哈,卻和暖如春蔓钟,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背卵贱。 一陣腳步聲響...
    開封第一講書人閱讀 32,983評論 1 269
  • 我被黑心中介騙來泰國打工滥沫, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人键俱。 一個月前我還...
    沈念sama閱讀 48,048評論 3 370
  • 正文 我出身青樓佣谐,卻偏偏與公主長得像,于是被迫代替她去往敵國和親方妖。 傳聞我的和親對象是個殘疾皇子狭魂,可洞房花燭夜當晚...
    茶點故事閱讀 44,864評論 2 354

推薦閱讀更多精彩內容