Error: failed to start container " executable file not found in $PATH: unknown"

3/12/2021

I am very new to docker Kubernetes. I have made my cluster of 3 nodes now I am creating a YAML file for pod creation. I have taken the image from https://github.com/utkudarilmaz/docker-hping3 the image name is utkudarilmaz/hping3. Can someone help me to set the command or the docker file in the path? because I cannot understand the problem. I want to run my pod successfully working so, that I can utilize it. My YAML file like

---
 apiVersion: v1
 kind: Pod
 metadata:
   name: second
   labels:
     app: web
 spec:
   containers:
     - name:  hping3
       image: utkudarilmaz/hping3
       command: ["hping3 [IP_ADDRESS"]
       ports:
         - containerPort: 80
   nodeSelector:
       disktype: ssd

if I do not specify command my pod status is CrashLoopBackOff. I have searched and found that https://stackoverflow.com/questions/41604499/my-kubernetes-pods-keep-crashing-with-crashloopbackoff-but-i-cant-find-any-lo I need a command to run the container continuously otherwise it goes in the cycle if I specify a command in YAML file like an above command: "hping3 103.22.221.59" and then when I run

kubectl exec –it second – hping3 [IP_ADDRESS]

I get

error: unable to upgrade connection: container not found ("hping3")

the output of kubectl decribe pod second

Events:
  Type     Reason     Age                   From               Message
  ----     ------     ----                  ----               -------
  Normal   Scheduled  3m39s                 default-scheduler  Successfully assigned default/second1 to netcs
  Normal   Pulled     3m35s                 kubelet            Successfully pulled image "utkudarilmaz/hping3" in 2.714028668s
  Normal   Pulled     3m31s                 kubelet            Successfully pulled image "utkudarilmaz/hping3" in 2.734426606s
  Normal   Pulled     3m15s                 kubelet            Successfully pulled image "utkudarilmaz/hping3" in 2.61256593s
  Normal   Pulled     2m46s                 kubelet            Successfully pulled image "utkudarilmaz/hping3" in 2.65727147s
  Warning  BackOff    2m11s (x5 over 3m4s)  kubelet            Back-off restarting failed container
  Normal   Pulling    2m4s (x5 over 3m38s)  kubelet            Pulling image "utkudarilmaz/hping3"
  Normal   Created    119s (x5 over 3m35s)  kubelet            Created container hping3
Warning  Failed     119s (x5 over 3m35s)  kubelet            Error: failed to start container "hping3": Error response from daemon: OCI runtime create failed: container_linux.go:370: starting container process caused: exec: "hping3 103.22.221.59": executable file not found in $PATH: unknown


  Normal   Pulled     119s                  kubelet            Successfully pulled image "utkudarilmaz/hping3" in 5.128803062s

Some Output of docker inspect $utkudarilmaz/hping3

"Mounts": [],
        "Config": {
            "Hostname": "104e9920881b",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": true,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": null,
            "Image": "utkudarilmaz/hping3",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": [
                "hping3"
            ],
            "OnBuild": null,
            "Labels": {
                "desription": "hping3 tool building on Alpine:latest",
                "version": "1.0"

my container will not continue running when I try this command

command: [ "/bin/bash", "-c", "--" ]
    args: [ "while true; do sleep 30; done;" ] from 
https://stackoverflow.com/questions/31870222/how-can-i-keep-a-container-running-on-kubernetes/40093356

same error file not found in the path

-- goody
docker
kubernetes

1 Answer

3/12/2021

First of all, you don't need to specify containerPort here as there is nothing listening on any tcp port in your hping3 container:

$ kubectl exec -ti second -- /bin/sh                                                                               
/ # netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name

In fact you don't even need to provide any command as hping3 is already defined as an ENTRYPOINT in this docker image and you don't really need to overwrite it. All you need in order to run your hping3 Pod is the following yaml manifest:

apiVersion: v1
kind: Pod
metadata:
  name: second
spec:
  containers:
    - name:  hping3
      image: utkudarilmaz/hping3
      args: ["IP-address"]

Yes, providing some args is obligatory in this case, otherwise your container will fall into CrashLoopBackOff state.

As you can read in the very brief description of the image in its README.md:

Usage:

docker pull utkudarilmaz/hping3:latest
docker run utkudarilmaz/hping3:latest [parameters] target_ip

providing target_ip is obligatory, but you don't have to provide anything else.

Although the above usage description doesn't say anything about running this image on kubernetes, such short description should be totally enough for us and we should be able to translate it "from docker to kubernetes language".

Take a look at the following section, titled Define a Command and Arguments for a Container, in the official kubernetes docs, especially this fragment:

enter image description here

When you override the default Entrypoint and Cmd, these rules apply:

  • If you do not supply command or args for a Container, the defaults defined in the Docker image are used.

  • If you supply a command but no args for a Container, only the supplied command is used. The default EntryPoint and the default Cmd defined in the Docker image are ignored.

  • If you supply only args for a Container, the default Entrypoint defined in the Docker image is run with the args that you supplied.
  • If you supply a command and args, the default Entrypoint and the default Cmd defined in the Docker image are ignored. Your command is run with your args.

From the above we are particularly interested in the third point:

  • If you supply only args for a Container, the default Entrypoint defined in the Docker image is run with the args that you supplied.

which means that in our kubernetes Pod definition we may supply only args and it's totally fine. As the ENTRYPOINT is already defined in the utkudarilmaz/hping3 image, there is no need to overwrite it by defining a command.

I was able to reproduce the error messsage you get only when trying to connect to hping3 container in CrashLoopBackOff state:

$ kubectl exec -ti second -- hping3 [IP-address]                                                                  
error: unable to upgrade connection: container not found ("hping3")

But when it runs, kubectl exec works without any issues:

$ kubectl exec -ti second -- hping3 [IP-address]
HPING [IP-address] (eth0 [IP-address]): NO FLAGS are set, 40 headers + 0 data bytes

Btw. hyphens in your command look a bit strange and they are not exactly the same characters as - and are not interpreted correctly when copied from the code snippet in your question, leading to strange errors like the following:

Error from server (NotFound): pods "–it" not found

So please mind the exact characters that you use in your commands.

As to the explanation of the error message you see when you kubectl describe your Pod:

"hping3 [IP-address]": executable file not found in $PATH: unknown

it says clearly that an executable named "hping3 IP-address" (yes, name of a single file!) cannot be found in your $PATH and I'm sure you don't have executable with such name πŸ˜‰

If you provide a command this way:

command: ["hping3 [IP-address]"]

keep in mind that the whole string between the double quotes is interpreted as a single command / executable. That's why it was trying to look for executable file named "hping3 IP-address" but for obvious reasons it couldn't find it.

As already mentioned in comments, the correct usage of the command field can be:

command: ["hping3","[IP-address]"]

but in your case you don't really need it.

I hope the above explanation was helpful.

-- mario
Source: StackOverflow