can not execute linux commands in the image

11/16/2021

i use minikube to launch containers in mac and am able to spin up the container but i am unable to run commands like ls and get error(otel-collector-lzvwv is the pod name):

kubectl exec --namespace="adalyu-k8s" --stdin --tty otel-collector-lzvwv -- ls

OCI runtime exec failed: exec failed: container_linux.go:380: starting container process caused: exec: "ls": executable file not found in $PATH: unknown
command terminated with exit code 126

i suspect there is something wrong with the image but it's the first time i saw i can run the program but unable to run commands like ls so i am wondering what i should do to make it avaialable. below is the description of the pod which contains the image:

kubernetes git:(main) ✗ kubectl describe po -n adalyu-k8s otel-collector-lzvw
Name:         otel-collector-lzvwv
Namespace:    adalyu-k8s
Priority:     0
Node:         minikube/192.168.49.2
Start Time:   Tue, 16 Nov 2021 22:18:41 +0800
Labels:       app=opentelemetry
              component=otel-collector
              controller-revision-hash=6bbb66bc8d
              pod-template-generation=1
Annotations:  <none>
Status:       Running
IP:           172.17.0.2
IPs:
  IP:           172.17.0.2
Controlled By:  DaemonSet/otel-collector
Containers:
  otel-collector:
    Container ID:   docker://22a4aa11d6e7c3ea9b03434bab4de6aa69279ed2424e95183d7c36ef4fe05c90
    Image:          otel/opentelemetry-collector-contrib:0.37.1
    Image ID:       docker-pullable://otel/opentelemetry-collector-contrib@sha256:7193b50f65daf4a915ecdec928faa4c965a0f1b264f13aa37d516d0459569dac
    Port:           <none>
    Host Port:      <none>
    State:          Running
      Started:      Tue, 16 Nov 2021 22:18:43 +0800
    Ready:          True
    Restart Count:  0
    Limits:
      cpu:     100m
      memory:  200Mi
    Requests:
      cpu:        100m
      memory:     200Mi
    Environment:  <none>
    Mounts:
      /etc/otel/config.yaml from data (ro,path="config.yaml")
      /var/lib/docker/containers from varlibdockercontainers (ro)
      /var/log from varlog (ro)
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-dvr8p (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
-- dashenswen
docker
kubernetes

1 Answer

11/16/2021

There could be chances that image is not supporting the bash however, also try with -it first

kubectl exec -it --namespace="adalyu-k8s" --stdin --tty otel-collector-lzvwv -- /bin/bash or /bin/sh

and check ls command working or not

i would suggest checking with the sh instead of the bash

kubectl exec --namespace="adalyu-k8s" --stdin --tty otel-collector-lzvwv -- /bin/sh

/bin/sh
-- Harsh Manvar
Source: StackOverflow