8.2. 更新日志转发自定义资源
OpenShift Container Platform Log Forward API 已从 OpenShift Container Platform 4.6 中的技术预览提升为正式发布。GA 发行版本包含一些改进和增强,需要您更改 ClusterLogging 自定义资源(CR),并将 LogForwarding 自定义资源(CR)替换为 ClusterLogForwarder CR。
OpenShift Container Platform 4.6 中的 ClusterLogForwarder 实例示例
apiVersion: logging.openshift.io/v1
kind: ClusterLogForwarder
metadata:
name: instance
namespace: openshift-logging
....
spec:
outputs:
- url: http://remote.elasticsearch.com:9200
name: elasticsearch
type: elasticsearch
- url: tls://fluentdserver.example.com:24224
name: fluentd
type: fluentdForward
secret:
name: fluentdserver
pipelines:
- inputRefs:
- infrastructure
- application
name: mylogs
outputRefs:
- elasticsearch
- inputRefs:
- audit
name: auditlogs
outputRefs:
- fluentd
- default
...
OpenShift Container Platform 4.5 中的 ClusterLogForwarder CR 示例
apiVersion: logging.openshift.io/v1alpha1
kind: LogForwarding
metadata:
name: instance
namespace: openshift-logging
spec:
disableDefaultForwarding: true
outputs:
- name: elasticsearch
type: elasticsearch
endpoint: remote.elasticsearch.com:9200
- name: fluentd
type: forward
endpoint: fluentdserver.example.com:24224
secret:
name: fluentdserver
pipelines:
- inputSource: logs.infra
name: infra-logs
outputRefs:
- elasticearch
- inputSource: logs.app
name: app-logs
outputRefs:
- elasticearch
- inputSource: logs.audit
name: audit-logs
outputRefs:
- fluentd
以下操作过程显示了您必须更改的每个参数。
流程
要将 4.5 中的 ClusterLogForwarder CR 更新至 ClusterLogForwarding CR 4.6,请进行以下修改:
编辑
ClusterLogging自定义资源(CR)以删除logforwardingtechpreview注解:ClusterLoggingCR 示例apiVersion: "logging.openshift.io/v1" kind: "ClusterLogging" metadata: annotations: clusterlogging.openshift.io/logforwardingtechpreview: enabled1 name: "instance" namespace: "openshift-logging" ....- 1
- 删除
logforwardingtechpreview注解。
导出
ClusterLogForwarderCR,为ClusterLogForwarder实例创建一个 YAML 文件:$ oc get LogForwarding instance -n openshift-logging -o yaml| tee ClusterLogForwarder.yaml编辑 YAML 文件进行以下修改:
OpenShift Container Platform 4.6 中的
ClusterLogForwarder实例示例apiVersion: logging.openshift.io/v11 kind: ClusterLogForwarder2 metadata: name: instance namespace: openshift-logging .... spec:3 outputs: - url: http://remote.elasticsearch.com:92004 name: elasticsearch type: elasticsearch - url: tls://fluentdserver.example.com:24224 name: fluentd type: fluentdForward5 secret: name: fluentdserver pipelines: - inputRefs:6 - infrastructure - application name: mylogs outputRefs: - elasticsearch - inputRefs: - audit name: auditlogs outputRefs: - fluentd - default7 ...- 1
- 将
apiVersion从"logging.openshift.io/v1alpha1"改为"logging.openshift.io/v1"。 - 2
- 将对象类型从
kind: "LogForwarding"改为kind: "ClusterLogForwarder"。 - 3
- 删除
disableDefaultForwarding: true参数。 - 4
- 将 output 参数从
spec.outputs.endpoint改为spec.outputs.url。如果 URL 没有前缀,请在 URL 中添加前缀,如https://、tcp://等。 - 5
- 对于 Fluentd 输出,请将
type从forward改为fluentdForward。 - 6
- 更改管道:
-
将
spec.pipelines.inputSource更改为spec.pipelines.inputRefs -
将
logs.infra改为infrastructure -
将
logs.app改为application -
将
logs.audit改为audit
-
将
- 7
- 可选:添加一个
default管道来将日志发送到内部 Elasticsearch 实例。您不需要配置default输出。注意如果您只希望将日志转发到内部 OpenShift Container Platform Elasticsearch 实例,请不要配置 Log Forwarding API。
创建 CR 对象。
$ oc create -f ClusterLogForwarder.yaml
有关 Log Forwarding API 新功能的信息,请参阅将日志转发到第三方系统。