8.10. 配置 PTP
精确时钟协议 (PTP) 硬件只是技术预览功能。技术预览功能不被红帽产品服务等级协议 (SLA) 支持,且可能在功能方面有缺陷。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。
有关红帽技术预览功能支持范围的详情,请参阅 https://access.redhat.com/support/offerings/techpreview/。
8.10.1. 关于 PTP 硬件
OpenShift Container Platform 包含在节点上使用 PTP 硬件的能力。您可以使用 PTP 硬件在节点上配置 linuxptp 服务。
PTP Operator 可以与在裸机基础架构上置备的集群中的带有 PTP 功能的设备一同工作。
您可以通过部署 PTP Operator,使用 OpenShift Container Platform 控制台来安装 PTP。PTP Operator 会创建和管理 linuxptp 服务。Operator 提供以下功能:
- 在集群中发现具有 PTP 功能的设备。
- 管理 linuxptp 服务的配置。
8.10.2. 安装 PTP Operator
作为集群管理员,您可以使用 OpenShift Container Platform CLI 或 Web 控制台来安装 PTP Operator。
8.10.2.1. CLI:安装 PTP Operator
作为集群管理员,您可以使用 CLI 安装 Operator。
先决条件
- 在裸机中安装有支持 PTP 硬件的节点的集群。
-
安装 OpenShift CLI(
oc
)。 -
以具有
cluster-admin
特权的用户身份登录。
流程
要为 PTP Operator 创建命名空间,输入以下命令:
$ cat << EOF| oc create -f - apiVersion: v1 kind: Namespace metadata: name: openshift-ptp labels: openshift.io/run-level: "1"
要为 Operator 创建 Operator 组,输入以下命令:
$ cat << EOF| oc create -f - apiVersion: operators.coreos.com/v1 kind: OperatorGroup metadata: name: ptp-operators namespace: openshift-ptp spec: targetNamespaces: - openshift-ptp EOF
订阅 PTP Operator。
运行以下命令,将 OpenShift Container Platform 主版本和次版本设置为环境变量,该变量在下一步中作为
channel
的值。$ OC_VERSION=$(oc version -o yaml | grep openshiftVersion | \ grep -o '[0-9]*[.][0-9]*' | head -1)
要为 PTP Operator 创建订阅,输入以下命令:
$ cat << EOF| oc create -f - apiVersion: operators.coreos.com/v1alpha1 kind: Subscription metadata: name: ptp-operator-subscription namespace: openshift-ptp spec: channel: "${OC_VERSION}" name: ptp-operator source: redhat-operators sourceNamespace: openshift-marketplace EOF
要验证是否已安装 Operator,请输入以下命令:
$ oc get csv -n openshift-ptp \ -o custom-columns=Name:.metadata.name,Phase:.status.phase
输出示例
Name Phase ptp-operator.4.4.0-202006160135 Succeeded
8.10.2.2. Web 控制台:安装 PTP Operator
作为集群管理员,您可以使用 Web 控制台安装 Operator。
如上一节所述,您必须创建命名空间和 operator 组。
流程
使用 OpenShift Container Platform Web 控制台安装 PTP Operator:
- 在 OpenShift Container Platform Web 控制台中,点击 Operators → OperatorHub。
- 从可用的 Operator 列表中选择 PTP Operator,然后点 Install。
- 在 Create Operator Subscription 页面中,在 A specific namespace on the cluster 下选择 openshift-ptp。然后,点击 Subscribe。
可选:验证是否成功安装了 PTP Operator:
- 切换到 Operators → Installed Operators 页面。
确保 openshift-ptp 项目中列出的 PTP Operator 的 Status 为 InstallSucceeded。
注意在安装过程中,Operator 可能会显示 Failed 状态。如果安装过程结束后有 InstallSucceeded 信息,您可以忽略这个 Failed 信息。
如果 Operator 没有被成功安装,请按照以下步骤进行故障排除:
- 进入 Operators → Installed Operators 页面,检查 Operator Subscriptions 和 Install Plans 选项卡中的 Status 项中是否有任何错误。
-
进入 Workloads → Pods 页面,检查
openshift-ptp
项目中 pod 的日志。
8.10.3. 自动发现 PTP 网络设备
PTP Operator 将 NodePtpDevice.ptp.openshift.io
自定义资源定义(CRD)添加到 OpenShift Container Platform。PTP Operator 将搜索集群中每个节点上的具有 PTP 功能的网络设备。Operator 会为每个提供兼容 PTP 设备的节点创建和更新 NodePtpDevice
自定义资源(CR)对象。
为每个节点创建一个 CR,并共享与该节点相同的名称。.status.devices
列表提供有关节点上 PTP 设备的信息。
以下是由 PTP Operator 创建的 NodePtpDevice
CR 示例:
apiVersion: ptp.openshift.io/v1 kind: NodePtpDevice metadata: creationTimestamp: "2019-11-15T08:57:11Z" generation: 1 name: dev-worker-0 1 namespace: openshift-ptp 2 resourceVersion: "487462" selfLink: /apis/ptp.openshift.io/v1/namespaces/openshift-ptp/nodeptpdevices/dev-worker-0 uid: 08d133f7-aae2-403f-84ad-1fe624e5ab3f spec: {} status: devices: 3 - name: eno1 - name: eno2 - name: ens787f0 - name: ens787f1 - name: ens801f0 - name: ens801f1 - name: ens802f0 - name: ens802f1 - name: ens803
8.10.4. 配置 Linuxptp 服务
PTP Operator 将 PtpConfig.ptp.openshift.io
自定义资源定义 (CRD) 添加至 OpenShift Container Platform。您可以通过创建 PtpConfig
自定义资源(CR)对象来配置 Linuxptp 服务(ptp4l、phc2sys)。
先决条件
-
安装 OpenShift CLI(
oc
)。 -
以具有
cluster-admin
特权的用户身份登录。 - 已安装了 PTP Operator。
流程
创建以下
PtpConfig
CR,然后在<name>-ptp-config.yaml
文件中保存 YAML。使用配置的实际名称替换<name>
。apiVersion: ptp.openshift.io/v1 kind: PtpConfig metadata: name: <name> 1 namespace: openshift-ptp 2 spec: profile: 3 - name: "profile1" 4 interface: "ens787f1" 5 ptp4lOpts: "-s -2" 6 phc2sysOpts: "-a -r" 7 recommend: 8 - profile: "profile1" 9 priority: 10 10 match: 11 - nodeLabel: "node-role.kubernetes.io/worker" 12 nodeName: "dev-worker-0" 13
- 1
- 为
PtpConfig
CR 指定名称。 - 2
- 指定安装 PTP Operator 的命名空间。
- 3
- 指定包括一个或多个
profile
的数组。 - 4
- 指定用于唯一标识配置集(profile)对象的配置集对象名称。
- 5
- 指定
ptp4l
服务要使用的网络接口名称,如ens787f1
。 - 6
- 为
ptp4l
服务指定系统配置选项,如-s -2
。这不应该包含接口名称-i <interface>
和服务配置文件-f /etc/ptp4l.conf
,因为这些文件会被自动附加。 - 7
- 为
phc2sys
服务指定系统配置选项,如-a -r
。 - 8
- 指定包括一个或多个
recommend
对象的数组,该数组定义了如何将配置集
应用到节点的规则。 - 9
- 指定
profile
部分中定义的profile
对象名称。 - 10
- 使用
0
到99
之间的一个整数值指定priority
。大数值的优先级较低,因此优先级99
低于优先级10
。如果根据match
项中定义的规则,节点可以与多个配置集相匹配,具有最高优先级的配置集将被应用到那个节点。 - 11
- 使用
nodeLabel
或nodeName
指定match
规则。 - 12
- 使用节点对象中的
node.Labels
的key
指定nodeLabel
。 - 13
- 使用节点对象的
node.Name
指定nodeName
。
运行以下命令来创建 CR:
$ oc create -f <filename> 1
- 1
- 将
<filename>
替换为您在上一步中创建的文件的名称。
可选:检查
PtpConfig
配置集是否应用到与nodeLabel
或nodeName
匹配的节点。$ oc get pods -n openshift-ptp -o wide
输出示例
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES linuxptp-daemon-4xkbb 1/1 Running 0 43m 192.168.111.15 dev-worker-0 <none> <none> linuxptp-daemon-tdspf 1/1 Running 0 43m 192.168.111.11 dev-master-0 <none> <none> ptp-operator-657bbb64c8-2f8sj 1/1 Running 0 43m 10.128.0.116 dev-master-0 <none> <none> $ oc logs linuxptp-daemon-4xkbb -n openshift-ptp I1115 09:41:17.117596 4143292 daemon.go:107] in applyNodePTPProfile I1115 09:41:17.117604 4143292 daemon.go:109] updating NodePTPProfile to: I1115 09:41:17.117607 4143292 daemon.go:110] ------------------------------------ I1115 09:41:17.117612 4143292 daemon.go:102] Profile Name: profile1 1 I1115 09:41:17.117616 4143292 daemon.go:102] Interface: ens787f1 2 I1115 09:41:17.117620 4143292 daemon.go:102] Ptp4lOpts: -s -2 3 I1115 09:41:17.117623 4143292 daemon.go:102] Phc2sysOpts: -a -r 4 I1115 09:41:17.117626 4143292 daemon.go:116] ------------------------------------ I1115 09:41:18.117934 4143292 daemon.go:186] Starting phc2sys... I1115 09:41:18.117985 4143292 daemon.go:187] phc2sys cmd: &{Path:/usr/sbin/phc2sys Args:[/usr/sbin/phc2sys -a -r] Env:[] Dir: Stdin:<nil> Stdout:<nil> Stderr:<nil> ExtraFiles:[] SysProcAttr:<nil> Process:<nil> ProcessState:<nil> ctx:<nil> lookPathErr:<nil> finished:false childFiles:[] closeAfterStart:[] closeAfterWait:[] goroutine:[] errch:<nil> waitDone:<nil>} I1115 09:41:19.118175 4143292 daemon.go:186] Starting ptp4l... I1115 09:41:19.118209 4143292 daemon.go:187] ptp4l cmd: &{Path:/usr/sbin/ptp4l Args:[/usr/sbin/ptp4l -m -f /etc/ptp4l.conf -i ens787f1 -s -2] Env:[] Dir: Stdin:<nil> Stdout:<nil> Stderr:<nil> ExtraFiles:[] SysProcAttr:<nil> Process:<nil> ProcessState:<nil> ctx:<nil> lookPathErr:<nil> finished:false childFiles:[] closeAfterStart:[] closeAfterWait:[] goroutine:[] errch:<nil> waitDone:<nil>} ptp4l[102189.864]: selected /dev/ptp5 as PTP clock ptp4l[102189.886]: port 1: INITIALIZING to LISTENING on INIT_COMPLETE ptp4l[102189.886]: port 0: INITIALIZING to LISTENING on INIT_COMPLETE