7.18.2.2. 在 Red Hat Enterprise Linux CoreOS(RHCOS)8 上为 hostpath 置备程序配置 SELinux
在创建 HostPathProvisioner 自定义资源前,您必须配置 SELinux。要在 Red Hat Enterprise Linux CoreOS(RHCOS)8 worker 上配置 SELinux,您必须在每个节点上创建一个 MachineConfig 对象。
先决条件
在每个节点上为 hostpath 置备程序创建的持久性卷(PV)创建后端目录。
重要后备目录不得位于文件系统的根目录中,因为
/分区在 RHCOS 中是只读的。例如,您可以使用/var/<directory_name>而不是/<directory_name>。
流程
创建
MachineConfig文件。例如:$ touch machineconfig.yaml编辑该文件,确保包含希望 hostpath 置备程序在其中创建 PV 的目录。例如:
apiVersion: machineconfiguration.openshift.io/v1 kind: MachineConfig metadata: name: 50-set-selinux-for-hostpath-provisioner labels: machineconfiguration.openshift.io/role: worker spec: config: ignition: version: 3.1.0 systemd: units: - contents: | [Unit] Description=Set SELinux chcon for hostpath provisioner Before=kubelet.service [Service] ExecStart=/usr/bin/chcon -Rt container_file_t <backing_directory_path>1 [Install] WantedBy=multi-user.target enabled: true name: hostpath-provisioner.service- 1
- 指定希望置备程序在其中创建 PV 的后备目录。该目录不能位于文件系统的根目录(
/)中。
创建
MachineConfig对象:$ oc create -f machineconfig.yaml -n <namespace>