spec: central: db: isEnabled: Default (1) persistence: persistentVolumeClaim: (2) claimName: central-db size: 100Gi storageClassName: <storage-class-name>
通过 Red Hat Advanced Cluster Security for Kubernetes (RHACS) Operator 进行的升级会根据您在安装时选择的**更新批准**选项自动或手动执行。
升级时请遵循以下指南
如果 Central 的版本早于 3.74,则必须先升级到 3.74,然后再升级到 4.x 版本。有关将 Central 升级到 3.74 版本的信息,请参阅3.74 版本的升级文档。
从 3.74 版本升级基于 Operator 的 Central 部署时,首先确保 Operator 升级模式设置为Manual
。然后,按照4.0 版本的升级文档中的步骤将 Operator 升级到 4.0 版本,并确保 Central 在线。完成升级到 4.0 版本后,Red Hat 建议将 Central 升级到最新版本以获得完整的功能。
在升级 Red Hat Advanced Cluster Security for Kubernetes (RHACS) 版本之前,请完成以下步骤
如果从 3.74 版本升级,请验证您正在运行 RHACS Operator 3.74 的最新补丁版本。
备份现有的 Central 数据库。
如果您要升级的集群包含SecuredCluster
自定义资源 (CR),请将收集方法更改为CORE_BPF
。更多信息,请参见“更改收集方法”。
如果您要升级的集群包含SecuredCluster
CR,则必须确保在升级之前将每个节点的收集设置设置为CORE_BPF
。
在 OpenShift Container Platform Web 控制台中,转到 RHACS Operator 页面。
在顶部导航菜单中,选择**Secured Cluster**。
单击实例名称,例如,**stackrox-secured-cluster-services**。
使用以下任一方法更改设置:
在**表单视图**中,在**每个节点设置**→**收集器设置**→**收集**下,选择**CORE_BPF**。
单击**YAML**打开 YAML 编辑器,并找到spec.perNode.collector.collection
属性。如果值为KernelModule
或EBPF
,则将其更改为CORE_BPF
。
单击**保存**。
Central DB 服务需要持久性存储。如果您尚未为 Central 集群配置默认的 SSD 或高性能存储类,则必须更新Central
自定义资源以配置 Central DB 持久卷声明 (PVC) 的存储类。
如果您已经为 Central 配置了默认存储类,请跳过此部分。 |
使用以下配置更新 Central 自定义资源:
spec: central: db: isEnabled: Default (1) persistence: persistentVolumeClaim: (2) claimName: central-db size: 100Gi storageClassName: <storage-class-name>
1 | 您不得将IsEnabled 的值更改为Enabled 。 |
2 | 如果此声明存在,您的集群将使用现有声明,否则它将创建一个新的声明。 |
您必须在支持 PostgreSQL 13 的数据库实例中拥有一个数据库,以及一个具有以下权限的用户:
连接数据库的权限。
架构上的Usage
和Create
权限。
架构中所有表上的Select
、Insert
、Update
和Delete
权限。
架构中所有序列上的Usage
权限。
使用 OpenShift Container Platform Web 控制台或终端在已部署的命名空间中创建一个密码密钥。
在 OpenShift Container Platform Web 控制台中,转到**工作负载**→**密钥**页面。创建一个包含密钥password
和值的**键/值密钥**,该值是包含已配置数据库超级用户密码的纯文本文件的路径。
或者,在您的终端中运行以下命令:
$ oc create secret generic external-db-password \ (1)
--from-file=password=<password.txt> (2)
1 | 如果您使用 Kubernetes,请输入kubectl 代替oc 。 |
2 | 将password.txt 替换为包含纯文本密码的文件的路径。 |
在 OpenShift Container Platform Web 控制台中,转到 Red Hat Advanced Cluster Security for Kubernetes Operator 页面。在顶部导航栏中选择**Central**,然后选择要连接到数据库的实例。
转到**YAML 编辑器**视图。
对于db.passwordSecret.name
,指定您在前面步骤中创建的引用密钥。例如,external-db-password
。
对于db.connectionString
,请以keyword=value
格式指定连接字符串,例如,host=<host> port=5432 database=stackrox user=stackrox sslmode=verify-ca
对于db.persistence
,删除整个块。
如有必要,您可以通过在顶级规范下添加 TLS 块来指定 Central 以信任数据库证书的证书颁发机构,如下例所示:
使用以下配置更新 Central 自定义资源:
spec:
tls:
additionalCAs:
- name: db-ca
content: |
<certificate>
central:
db:
isEnabled: Default (1)
connectionString: "host=<host> port=5432 user=<user> sslmode=verify-ca"
passwordSecret:
name: external-db-password
1 | 您不得将IsEnabled 的值更改为Enabled 。 |
单击**保存**。
您可以使用 OpenShift Container Platform Web 控制台或命令行更改 RHACS Operator 的更新频道。要将 RHACS 从 3.74 升级到 4.0,必须更改更新频道。
您必须更改安装了 RHACS Operator 的所有集群(包括 Central 和所有受保护的集群)的订阅频道。 |
您必须验证您正在使用最新的 RHACS 3.74 Operator,并且没有任何待处理的手动 Operator 升级。
您必须验证您已备份 Central 数据库。
您可以使用具有cluster-admin
权限的帐户访问 OpenShift Container Platform 集群 Web 控制台。
使用以下说明使用 Web 控制台更改订阅频道:
在 OpenShift Container Platform Web 控制台的**管理员**视角中,转到**Operators**→**已安装的 Operators**。
单击 RHACS Operator。
单击**订阅**选项卡。
单击**更新频道**下的更新频道名称。
选择**stable**,然后单击**保存**。
对于具有**自动**批准策略的订阅,更新将自动开始。返回到**Operators**→**已安装的 Operators**页面以监控更新进度。完成后,状态将更改为**成功**和**最新**。
对于具有**手动**批准策略的订阅,您可以从**订阅**选项卡手动批准更新。
使用以下说明使用命令行更改订阅频道:
运行以下命令将订阅频道更改为stable
:
$ oc -n rhacs-operator \ (1)
patch subscriptions.operators.coreos.com rhacs-operator \
--type=merge --patch='{ "spec": { "channel": "stable" }}'
1 | 如果您使用 Kubernetes,请输入kubectl 代替oc 。 |
在更新期间,RHACS Operator 将配置一个名为central-db
的新部署,并且您的数据将开始迁移。这大约需要 30 分钟,并且只有在您升级后才会发生。
要回滚 Operator 升级,您必须执行以下部分中描述的步骤。您可以使用 CLI 或 OpenShift Container Platform Web 控制台回滚 Operator 升级。
如果您要从 RHACS 4.0 回滚,则只能回滚到 RHACS 3.74 的最新补丁版本。 |
您可以使用 CLI 命令回滚 Operator 版本。
运行以下命令删除 OLM 订阅:
对于 OpenShift Container Platform,运行以下命令:
$ oc -n rhacs-operator delete subscription rhacs-operator
对于 Kubernetes,运行以下命令:
$ kubectl -n rhacs-operator delete subscription rhacs-operator
运行以下命令删除集群服务版本 (CSV):
对于 OpenShift Container Platform,运行以下命令:
$ oc -n rhacs-operator delete csv -l operators.coreos.com/rhacs-operator.rhacs-operator
对于 Kubernetes,运行以下命令:
$ kubectl -n rhacs-operator delete csv -l operators.coreos.com/rhacs-operator.rhacs-operator
通过选择以下选项之一来确定要回滚到的先前版本:
如果当前 Central 实例正在运行,请运行以下命令查询 RHACS API 以获取回滚版本
$ curl -k -s -u <user>:<password> https://<central hostname>/v1/centralhealth/upgradestatus | jq -r .upgradeStatus.forceRollbackTo
如果当前 Central 实例未运行,请执行以下步骤
此过程仅适用于安装了 |
运行以下命令确保 Central 部署已缩容
对于 OpenShift Container Platform,运行以下命令:
$ oc scale -n <central namespace> –replicas=0 deploy/central
对于 Kubernetes,运行以下命令:
$ kubectl scale -n <central namespace> –replicas=0 deploy/central
将以下 pod 规范保存为 YAML 文件
apiVersion: v1
kind: Pod
metadata:
name: get-previous-db-version
spec:
containers:
- name: get-previous-db-version
image: registry.redhat.io/advanced-cluster-security/rhacs-main-rhel8:<rollback version>
command:
- sh
args:
- '-c'
- "cat /var/lib/stackrox/.previous/migration_version.yaml | grep '^image:' | cut -f 2 -d : | tr -d ' '"
volumeMounts:
- name: stackrox-db
mountPath: /var/lib/stackrox
volumes:
- name: stackrox-db
persistentVolumeClaim:
claimName: stackrox-db
使用您保存的 YAML 文件,运行以下命令在您的 Central 命名空间中创建一个 pod
对于 OpenShift Container Platform,运行以下命令:
$ oc create -n <central namespace> -f pod.yaml
对于 Kubernetes,运行以下命令:
$ kubectl create -n <central namespace> -f pod.yaml
pod 创建完成后,运行以下命令获取版本
对于 OpenShift Container Platform,运行以下命令:
$ oc logs -n <central namespace> get-previous-db-version
对于 Kubernetes,运行以下命令:
$ kubectl logs -n <central namespace> get-previous-db-version
运行以下命令编辑central-config.yaml
ConfigMap
以设置maintenance.forceRollBackVersion:<version>
参数
对于 OpenShift Container Platform,运行以下命令:
$ oc get configmap -n <central namespace> central-config -o yaml | sed -e "s/forceRollbackVersion: none/forceRollbackVersion: <version>/" | oc -n <central namespace> apply -f -
对于 Kubernetes,运行以下命令:
$ kubectl get configmap -n <central namespace> central-config -o yaml | sed -e "s/forceRollbackVersion: none/forceRollbackVersion: <version>/" | kubectl -n <central namespace> apply -f -
使用步骤 3 中显示的版本字符串作为镜像标签来设置 Central 部署的镜像。例如,运行以下命令
对于 OpenShift Container Platform,运行以下命令:
$ oc set image -n <central namespace> deploy/central central=registry.redhat.io/advanced-cluster-security/rhacs-main-rhel8:<version>
对于 Kubernetes,运行以下命令:
$ kubectl set image -n <central namespace> deploy/central central=registry.redhat.io/advanced-cluster-security/rhacs-main-rhel8:<version>
确保 Central pod 启动并具有ready
状态。如果 pod 崩溃,请检查日志以查看备份是否已恢复。成功的日志消息类似于以下示例
Clone to Migrate ".previous", ""
在回滚的通道上重新安装 Operator。例如,在rhacs-3.74
通道上安装3.74.2
。
您可以使用 OpenShift Container Platform Web 控制台回滚 Operator 版本。
您可以使用具有cluster-admin
权限的帐户访问 OpenShift Container Platform 集群 Web 控制台。
转到**Operators** → **Installed Operators**页面。
单击 RHACS Operator。
在**Operator Details**页面上,从**Actions**列表中选择**Uninstall Operator**。此操作之后,Operator 将停止运行,并且不再接收更新。
通过选择以下选项之一来确定要回滚到的先前版本:
如果当前 Central 实例正在运行,您可以从终端窗口运行以下命令查询 RHACS API 以获取回滚版本
$ curl -k -s -u <user>:<password> https://<central hostname>/v1/centralhealth/upgradestatus | jq -r .upgradeStatus.forceRollbackTo
您可以创建一个 pod 并通过执行以下步骤提取之前的版本
此过程仅适用于安装了 |
转到**Workloads** → **Deployments** → **central**。
在**Deployment details**下,单击 pod 计数旁边的向下箭头以缩减 pod。
转到**Workloads** → **Pods** → **Create Pod**并将 pod 规范的内容(如以下示例所示)粘贴到编辑器中
apiVersion: v1
kind: Pod
metadata:
name: get-previous-db-version
spec:
containers:
- name: get-previous-db-version
image: registry.redhat.io/advanced-cluster-security/rhacs-main-rhel8:<rollback version>
command:
- sh
args:
- '-c'
- "cat /var/lib/stackrox/.previous/migration_version.yaml | grep '^image:' | cut -f 2 -d : | tr -d ' '"
volumeMounts:
- name: stackrox-db
mountPath: /var/lib/stackrox
volumes:
- name: stackrox-db
persistentVolumeClaim:
claimName: stackrox-db
单击**Create**。
创建 pod 后,单击**Logs**选项卡以获取版本字符串。
通过执行以下步骤更新回滚配置
转到**Workloads** → **ConfigMaps** → **central-config**并从**Actions**列表中选择**Edit ConfigMap**。
在central-config.yaml
键的值中找到forceRollbackVersion
行。
将none
替换为3.73.3
,然后保存文件。
通过执行以下步骤将 Central 更新到早期版本
转到**Workloads** → **Deployments** → **central**并从Actions列表中选择**Edit Deployment**。
更新镜像名称,然后保存更改。
确保 Central pod 启动并具有ready
状态。如果 pod 崩溃,请检查日志以查看备份是否已恢复。成功的日志消息类似于以下示例
Clone to Migrate ".previous", ""
在回滚的通道上重新安装 Operator。例如,在rhacs-3.74
通道上安装3.74.2
。
请按照以下说明调查和解决 RHACS Operator 的升级相关问题。
请按照此处的说明排查升级期间 Central DB pod 失败的问题
检查central-db
pod 的状态
$ oc -n <namespace> get pod -l app=central-db (1)
1 | 如果您使用 Kubernetes,请输入kubectl 代替oc 。 |
如果 pod 的状态为Pending
,请使用 describe 命令获取更多详细信息
$ oc -n <namespace> describe po/<central-db-pod-name> (1)
1 | 如果您使用 Kubernetes,请输入kubectl 代替oc 。 |
您可能会看到FailedScheduling
警告消息
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedScheduling 54s default-scheduler 0/7 nodes are available: 1 Insufficient memory, 3 node(s) had untolerated taint {node-role.kubernetes.io/master: }, 4 Insufficient cpu. preemption: 0/7 nodes are available: 3 Preemption is not helpful for scheduling, 4 No preemption victims found for incoming pod.
此警告消息表明计划的节点内存不足,无法满足 pod 的资源需求。如果您拥有小型环境,请考虑增加节点上的资源或添加可以支持数据库的更大节点。
否则,请考虑减少central
→ db
→ resources
下自定义资源中central-db
pod 的资源需求。但是,运行的 Central 资源少于建议的最小值可能会导致 RHACS 的性能下降。
当 RHACS Operator 具有以下条件时,您必须检查自定义资源条件以查找问题
如果 Operator 无法部署 Central 或安全集群
如果 Operator 无法将 CR 更改应用于实际资源
对于 Central,运行以下命令以检查条件
$ oc -n rhacs-operator describe centrals.platform.stackrox.io (1)
1 | 如果您使用 Kubernetes,请输入kubectl 代替oc 。 |
对于安全集群,运行以下命令以检查条件
$ oc -n rhacs-operator describe securedclusters.platform.stackrox.io (1)
1 | 如果您使用 Kubernetes,请输入kubectl 代替oc 。 |
您可以从条件输出中识别配置错误
Conditions:
Last Transition Time: 2023-04-19T10:49:57Z
Status: False
Type: Deployed
Last Transition Time: 2023-04-19T10:49:57Z
Status: True
Type: Initialized
Last Transition Time: 2023-04-19T10:59:10Z
Message: Deployment.apps "central" is invalid: spec.template.spec.containers[0].resources.requests: Invalid value: "50": must be less than or equal to cpu limit
Reason: ReconcileError
Status: True
Type: Irreconcilable
Last Transition Time: 2023-04-19T10:49:57Z
Message: No proxy configuration is desired
Reason: NoProxyConfig
Status: False
Type: ProxyConfigFailed
Last Transition Time: 2023-04-19T10:49:57Z
Message: Deployment.apps "central" is invalid: spec.template.spec.containers[0].resources.requests: Invalid value: "50": must be less than or equal to cpu limit
Reason: InstallError
Status: True
Type: ReleaseFailed
此外,您可以查看 RHACS pod 日志以查找有关该问题的更多信息。运行以下命令以查看日志
oc -n rhacs-operator logs deploy/rhacs-operator-controller-manager manager (1)
1 | 如果您使用 Kubernetes,请输入kubectl 代替oc 。 |