部署wazuh-manager并在pod运行后替换ossec.conf- kubernetes

vwkv1x7d  于 2022-12-29  发布在  Kubernetes
关注(0)|答案(1)|浏览(94)

我正在kubernetes群集上部署wazuh-manager,需要从ossec.conf禁用某些安全检查功能,我正在尝试复制config-map ossec.conf(我的设置),但如果我在/var/ossec/etc/ossec.conf上创建“卷装载”,它将删除/var/ossec/etc/中的所有内容。(部署wazuh-manager pod时,它将复制此管理器需要的所有文件)。因此,我想创建一个新的卷装载"/wazuh/ossec.conf”,使用**“生命周期启动后睡眠〉执行命令“cp /wazuh/ossec.conf〉/var/ossec/etc/“,但我收到一个错误,”无法找到/var/ossec/etc/"。**

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: wazuh-manager
  labels:
    node-type: master
spec:
  replicas: 1
  selector:
    matchLabels:
      appComponent:  wazuh-manager
      node-type: master
  serviceName: wazuh
  template:
    metadata:
      labels:
        appComponent: wazuh-manager
        node-type: master
      name: wazuh-manager
    spec:
      volumes:
        - name: ossec-conf
          configMap:
            name: ossec-config
      containers:
        - name: wazuh-manager
          image: wazuh-manager4.8
          lifecycle:
            postStart:
              exec: 
                command: ["/bin/sh", "-c", "cp  /wazuh/ossec.conf >/var/ossec/etc/ossec.conf"]
          resources:
          securityContext:  
            capabilities:
              add: ["SYS_CHROOT"]
          volumeMounts:
            - name: ossec-conf
              mountPath: /wazuh/ossec.conf
              subPath: master.conf
              readOnly: true
          ports:
            - containerPort: 8855
              name: registration     
  volumeClaimTemplates:
    - metadata:
        name: wazuh-disk
      spec:
        accessModes: ReadWriteOnce
        storageClassName: wazuh-csi-disk
        resources:
          requests:
            storage: 50

错误:

$ kubectl get pods -n wazuh

wazuh-1670333556-0        0/1     PostStartHookError: command '/bin/sh -c cp  /wazuh/ossec.conf > /var/ossec/etc/ossec.conf' exited with 1: /bin/sh: /var/ossec/etc/ossec.conf: No such file or directory...
lx0bsm1f

lx0bsm1f1#

在wazuh-kubernetes存储库中,每个Wazuh管理器群集节点都有一个文件:

wazuh/wazuh管理器/wazuh配置文件/master.conf用于Wazuh管理器主节点。
wazuh/wazuh_manager/wazuh_conf/worker.conf用于Wazuh管理器工作节点。

使用这些文件,在Kustomization.yml脚本中创建配置Map:

configMapGenerator:
   -name: indexer-conf
     files:
       - indexer_stack/wazuh-indexer/indexer_conf/opensearch.yml
       - indexer_stack/wazuh-indexer/indexer_conf/internal_users.yml
   -name: wazuh-conf
     files:
       -wazuh_managers/wazuh_conf/master.conf
       -wazuh_managers/wazuh_conf/worker.conf
   -name: dashboard-conf
     files:
       - indexer_stack/wazuh-dashboard/dashboard_conf/opensearch_dashboards.yml

然后,在部署清单中挂载它们,以将配置持久保存在每个群集节点的ossec.conf文件中:

wazuh/wazuh_管理者/wazuh-管理者-sts.yaml

...
    specification:
       volumes:
         -name:config
           configMap:
             name: wazuh-conf 
...
     volumeMounts:
             -name:config
               mountPath: /wazuh-config-mount/etc/ossec.conf
               subPath: master.conf 
...

需要注意的是,您需要复制到**/var/ossec/目录中的配置文件必须挂载到/wazuh-config-mount/目录中,然后Wazuh管理器映像入口点负责将其复制到容器开头的位置。配置Map表将装载到/wazuh-config-mount/etc/ossec.conf**,然后在启动时复制到**/var/ossec/etc/ossec.conf**。

相关问题