如何将configMap文件传递给部署的命令参数?

问题描述 投票:0回答:1

我们正在尝试创建一个 yaml 文件,用于 Azure Dev Ops Release 管道来配置 otel-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

请找到下面的 yaml 并描述 pod:

apiVersion: v1
kind: ConfigMap
metadata:
  name: otel-collector-config
data:
  otel-collector-config.yaml: |-
    receivers:
  ...
---
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/

描述 pod 给出以下响应

| Name:             otel-collector-deployment-6fd9d96d75-k28bt                                                                                                                                                                                                                         │
│ Namespace:        default                                                                                                                                                                                                                                                            │
│ Priority:         0                                                                                                                                                                                                                                                                  │
│ Service Account:  default                                                                                                                                                                                                                                                            │
│ Node:             srv-oms-core/192.168.77.93                                                                                                                                                                                                                                         │
│ Start Time:       Tue, 26 Dec 2023 20:29:40 +0530                                                                                                                                                                                                                                    │
│ Labels:           app=otel-collector                                                                                                                                                                                                                                                 │
│                   pod-template-hash=6fd9d96d75                                                                                                                                                                                                                                       │
│ Annotations:      cni.projectcalico.org/containerID: 9918293acb1f9e8f87d2eb90b15c1c978e928d5d90d7d8b66f113193ed637ab2                                                                                                                                                                │
│                   cni.projectcalico.org/podIP: 10.1.107.25/32                                                                                                                                                                                                                        │
│                   cni.projectcalico.org/podIPs: 10.1.107.25/32                                                                                                                                                                                                                       │
│ Status:           Running                                                                                                                                                                                                                                                            │
│ IP:               10.1.107.25                                                                                                                                                                                                                                                        │
│ IPs:                                                                                                                                                                                                                                                                                 │
│   IP:           10.1.107.25                                                                                                                                                                                                                                                          │
│ Controlled By:  ReplicaSet/otel-collector-deployment-6fd9d96d75                                                                                                                                                                                                                      │
│ Containers:                                                                                                                                                                                                                                                                          │
│   otel-collector:                                                                                                                                                                                                                                                                    │
│     Container ID:  containerd://4b0ba86729d941cbf396562d07b6a56a94613bf9d86419a3b22538fd9c82be5a                                                                                                                                                                                     │
│     Image:         otel/opentelemetry-collector-contrib:0.88.0                                                                                                                                                                                                                       │
│     Image ID:      docker.io/otel/opentelemetry-collector-contrib@sha256:13092c22704b62ecedaa5a1fad2c699c15101fefbc902ba39f391a47c191e195                                                                                                                                            │
│     Port:          4317/TCP                                                                                                                                                                                                                                                          │
│     Host Port:     0/TCP                                                                                                                                                                                                                                                             │
│     Command:                                                                                                                                                                                                                                                                         │
│       --config=/etc/otel-collector-config.yaml                                                                                                                                                                                                                                       │
│       --feature-gates=pkg.translator.prometheus.NormalizeName                                                                                                                                                                                                                        │
│     State:          Waiting                                                                                                                                                                                                                                                          │
│       Reason:       CrashLoopBackOff                                                                                                                                                                                                                                                 │
│     Last State:     Terminated                                                                                                                                                                                                                                                       │
│       Reason:       StartError                                                                                                                                                                                                                                                       │
│       Message:      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                                                                                                                                                                                                                                                                  │
│       Exit Code:    128                                                                                                                                                                                                                                                              │
│       Started:      Thu, 01 Jan 1970 05:30:00 +0530                                                                                                                                                                                                                                  │
│       Finished:     Tue, 26 Dec 2023 21:21:43 +0530                                                                                                                                                                                                                                  │
│     Ready:          False                                                                                                                                                                                                                                                            │
│     Restart Count:  15                                                                                                                                                                                                                                                               │
│     Environment:    <none>                                                                                                                                                                                                                                                           │
│     Mounts:                                                                                                                                                                                                                                                                          │
│       /etc/otel-collector-config.yaml from config (rw,path="otel-collector-config.yaml")                                                                                                                                                                                             │
│       /log/applogs from logsdirectory (rw)                                                                                                                                                                                                                                           │
│       /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-9w8xp (ro)                                                                                                                                                                                                  │
│ Conditions:                                                                                                                                                                                                                                                                          │
│   Type              Status                                                                                                                                                                                                                                                           │
│   Initialized       True                                                                                                                                                                                                                                                             │
│   Ready             False                                                                                                                                                                                                                                                            │
│   ContainersReady   False                                                                                                                                                                                                                                                            │
│   PodScheduled      True                                                                                                                                                                                                                                                             │
│ Volumes:                                                                                                                                                                                                                                                                             │
│   config:                                                                                                                                                                                                                                                                            │
│     Type:      ConfigMap (a volume populated by a ConfigMap)                                                                                                                                                                                                                         │
│     Name:      otel-collector-config                                                                                                                                                                                                                                                 │
│     Optional:  false                                                                                                                                                                                                                                                                 │
│   logsdirectory:                                                                                                                                                                                                                                                                     │
│     Type:          HostPath (bare host directory volume)                                                                                                                                                                                                                             │
│     Path:          /volumes/logs/                                                                                                                                                                                                                                                    │
│     HostPathType:                                                                                                                                                                                                                                                                    │
│   kube-api-access-9w8xp:                                                                                                                                                                                                                                                             │
│     Type:                    Projected (a volume that contains injected data from multiple sources)
│     TokenExpirationSeconds:  3607                                                                                                                                                                                                                                                    │
│     ConfigMapName:           kube-root-ca.crt                                                                                                                                                                                                                                        │
│     ConfigMapOptional:       <nil>                                                                                                                                                                                                                                                   │
│     DownwardAPI:             true                                                                                                                                                                                                                                                    │
│ QoS Class:                   BestEffort                                                                                                                                                                                                                                              │
│ Node-Selectors:              <none>                                                                                                                                                                                                                                                  │
│ Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s                                                                                                                                                                                               │
│                              node.kubernetes.io/unreachable:NoExecute op=Exists for 300s                                                                                                                                                                                             │
│ Events:                                                                                                                                                                                                                                                                              │
│   Type     Reason   Age                   From     Message                                                                                                                                                                                                                           │
│   ----     ------   ----                  ----     -------                                                                                                                                                                                                                           │
│   Warning  BackOff  116s (x256 over 56m)  kubelet  Back-off restarting failed container otel-collector in pod otel-collector-deployment-6fd9d96d75-k28bt_default(6e383691-eab6-40fd-a0e2-7d955bb9b0e8)
kubectl configmap kubernetes-deployment
1个回答
0
投票

容器图像二进制文件是

otelcol-contrib
而不是
otelcol
,请参阅 图像层

当您使用

command
时,您将覆盖容器映像入口点,因此您必须提供二进制文件:

command:
- "/otelcol-contrib"
- "--config=/etc/otel-collector-config.yaml"
- "--feature-gates=pkg.translator.prometheus.NormalizeName"

或者:

command:
- "/otelcol-contrib"
args:
- "--config=/etc/otel-collector-config.yaml"
- "--feature-gates=pkg.translator.prometheus.NormalizeName"

但是,因为您随后使用的是默认的

entrypoint
,所以可以省略
command

args:
- "--config=/etc/otel-collector-config.yaml"
- "--feature-gates=pkg.translator.prometheus.NormalizeName"
© www.soinside.com 2019 - 2024. All rights reserved.