如何将ConfigMap传入Deployment命令参数?Otel-Collector启动失败求助
问题排查:OpenTelemetry Collector Pod启动失败
核心报错
failed to create containerd task: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "--config=/etc/otel-collector-config.yaml": stat --config=/etc/otel-collector-config.yaml: no such file or directory: unknown
现有配置文件
ConfigMap配置
apiVersion: v1 kind: ConfigMap metadata: name: otel-collector-config data: otel-collector-config.yaml: |- receivers: ... ---
Deployment配置
apiVersion: apps/v1 kind: Deployment metadata: name: otel-collector-deployment spec: replicas: 1 selector: matchLabels: app: otel-collector template: metadata: labels: app: otel-collector spec: containers: - name: otel-collector image: otel/opentelemetry-collector-contrib:0.88.0 ports: - containerPort: 4317 command: - "--config=/etc/otel-collector-config.yaml" - "--feature-gates=pkg.translator.prometheus.NormalizeName" volumeMounts: - name: config subPath: otel-collector-config.yaml mountPath: /etc/otel-collector-config.yaml - name: logsdirectory mountPath: /log/applogs volumes: - name: config configMap: name: otel-collector-config - name: logsdirectory hostPath: path: /volumes/logs/
问题根因
Kubernetes容器的command字段用于指定启动时执行的可执行程序路径,而非参数。当前配置错误地将启动参数直接放在command数组中,导致系统尝试执行--config=/etc/otel-collector-config.yaml这个不存在的程序,触发启动失败。
解决方案
有两种合规的配置方式:
方式1:明确指定可执行程序 + 用args传参
containers: - name: otel-collector image: otel/opentelemetry-collector-contrib:0.88.0 ports: - containerPort: 4317 command: ["otelcol-contrib"] # 指定镜像内置的可执行文件 args: - "--config=/etc/otel-collector-config.yaml" - "--feature-gates=pkg.translator.prometheus.NormalizeName" volumeMounts: - name: config subPath: otel-collector-config.yaml mountPath: /etc/otel-collector-config.yaml - name: logsdirectory mountPath: /log/applogs
方式2:仅用args覆盖默认参数(推荐)
该镜像默认启动命令即为otelcol-contrib,无需修改command,直接通过args传递自定义参数即可:
containers: - name: otel-collector image: otel/opentelemetry-collector-contrib:0.88.0 ports: - containerPort: 4317 args: - "--config=/etc/otel-collector-config.yaml" - "--feature-gates=pkg.translator.prometheus.NormalizeName" volumeMounts: - name: config subPath: otel-collector-config.yaml mountPath: /etc/otel-collector-config.yaml - name: logsdirectory mountPath: /log/applogs
验证操作
应用修改后的配置:
kubectl apply -f <你的Deployment配置文件名>.yaml
检查Pod状态确认是否正常启动:
kubectl get pods
内容的提问来源于stack exchange,提问作者Durgesh Chaudhary
相关产品推荐
相关产品推荐

