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.2.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>