3.6. Moving etcd to a different disk


You can move etcd from a shared disk to a separate disk to prevent or resolve performance issues.

The Machine Config Operator (MCO) is responsible for mounting a secondary disk for OpenShift Container Platform 4.21 container storage.

注意

This encoded script only supports device names for the following device types:

SCSI or SATA
/dev/sd*
Virtual device
/dev/vd*
NVMe
/dev/nvme*[0-9]*n*

Limitations

  • When the new disk is attached to the cluster, the etcd database is part of the root mount. It is not part of the secondary disk or the intended disk when the primary node is recreated. As a result, the primary node will not create a separate /var/lib/etcd mount.

Prerequisites

  • You have a backup of your cluster’s etcd data.
  • You have installed the OpenShift CLI (oc).
  • You have access to the cluster with cluster-admin privileges.
  • Add additional disks before uploading the machine configuration.
  • The MachineConfigPool must match metadata.labels[machineconfiguration.openshift.io/role]. This applies to a controller, worker, or a custom pool.
注意

This procedure does not move parts of the root file system, such as /var/, to another disk or partition on an installed node.

重要

This procedure is not supported when using control plane machine sets.

Procedure

  1. Attach the new disk to the cluster and verify that the disk is detected in the node by running the lsblk command in a debug shell:

    $ oc debug node/<node_name>
    # lsblk

    Note the device name of the new disk reported by the lsblk command.

  2. Create the following script and name it etcd-find-secondary-device.sh:

    #!/bin/bash
    set -uo pipefail
    
    for device in <device_type_glob>; do 
    1
    
    /usr/sbin/blkid "${device}" &> /dev/null
     if [ $? == 2  ]; then
        echo "secondary device found ${device}"
        echo "creating filesystem for etcd mount"
        mkfs.xfs -L var-lib-etcd -f "${device}" &> /dev/null
        udevadm settle
        touch /etc/var-lib-etcd-mount
        exit
     fi
    done
    echo "Couldn't find secondary block device!" >&2
    exit 77
    1
    Replace <device_type_glob> with a shell glob for your block device type. For SCSI or SATA drives, use /dev/sd*; for virtual drives, use /dev/vd*; for NVMe drives, use /dev/nvme*[0-9]*n*.
  3. Create a base64-encoded string from the etcd-find-secondary-device.sh script and note its contents:

    $ base64 -w0 etcd-find-secondary-device.sh
  4. Create a MachineConfig YAML file named etcd-mc.yml with contents such as the following:

    apiVersion: machineconfiguration.openshift.io/v1
    kind: MachineConfig
    metadata:
      labels:
        machineconfiguration.openshift.io/role: master
      name: 98-var-lib-etcd
    spec:
      config:
        ignition:
          version: 3.5.0
        storage:
          files:
            - path: /etc/find-secondary-device
              mode: 0755
              contents:
                source: data:text/plain;charset=utf-8;base64,<encoded_etcd_find_secondary_device_script> 
    1
    
        systemd:
          units:
            - name: find-secondary-device.service
              enabled: true
              contents: |
                [Unit]
                Description=Find secondary device
                DefaultDependencies=false
                After=systemd-udev-settle.service
                Before=local-fs-pre.target
                ConditionPathExists=!/etc/var-lib-etcd-mount
    
                [Service]
                RemainAfterExit=yes
                ExecStart=/etc/find-secondary-device
    
                RestartForceExitStatus=77
    
                [Install]
                WantedBy=multi-user.target
            - name: var-lib-etcd.mount
              enabled: true
              contents: |
                [Unit]
                Before=local-fs.target
    
                [Mount]
                What=/dev/disk/by-label/var-lib-etcd
                Where=/var/lib/etcd
                Type=xfs
                TimeoutSec=120s
    
                [Install]
                RequiredBy=local-fs.target
            - name: sync-var-lib-etcd-to-etcd.service
              enabled: true
              contents: |
                [Unit]
                Description=Sync etcd data if new mount is empty
                DefaultDependencies=no
                After=var-lib-etcd.mount var.mount
                Before=crio.service
    
                [Service]
                Type=oneshot
                RemainAfterExit=yes
                ExecCondition=/usr/bin/test ! -d /var/lib/etcd/member
                ExecStart=/usr/sbin/setsebool -P rsync_full_access 1
                ExecStart=/bin/rsync -ar /sysroot/ostree/deploy/rhcos/var/lib/etcd/ /var/lib/etcd/
                ExecStart=/usr/sbin/semanage fcontext -a -t container_var_lib_t '/var/lib/etcd(/.*)?'
                ExecStart=/usr/sbin/setsebool -P rsync_full_access 0
                TimeoutSec=0
    
                [Install]
                WantedBy=multi-user.target graphical.target
            - name: restorecon-var-lib-etcd.service
              enabled: true
              contents: |
                [Unit]
                Description=Restore recursive SELinux security contexts
                DefaultDependencies=no
                After=var-lib-etcd.mount
                Before=crio.service
    
                [Service]
                Type=oneshot
                RemainAfterExit=yes
                ExecStart=/sbin/restorecon -R /var/lib/etcd/
                TimeoutSec=0
    
                [Install]
                WantedBy=multi-user.target graphical.target
    1
    Replace <encoded_etcd_find_secondary_device_script> with the encoded script contents that you noted.
  5. Apply the created MachineConfig YAML file:

    $ oc create -f etcd-mc.yml

Verification steps

  • Run the grep /var/lib/etcd /proc/mounts command in a debug shell for the node to ensure that the disk is mounted:

    $ oc debug node/<node_name>
    # grep -w "/var/lib/etcd" /proc/mounts

    Example output

    /dev/sdb /var/lib/etcd xfs rw,seclabel,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota 0 0

Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

关于红帽文档

Legal Notice

Theme

© 2026 Red Hat
返回顶部