Kubernetes: could not find file in command property file

11/23/2018

I use CentOs 7.4 virtual machine which has 32Gb memory.

I have docker composer, it has following configurations:

version: "2"
services:
  shiny-cas-server:
    image: shiny-cas
    command: puma -C config/puma.rb
    volumes:
      - ./cas-server/logs:/app/logs
      - ./cas-server/config:/app/config
      - ./cas-server/public:/app/public

With above docker level configuartions, I make kubernetes configuration:

cas-server-depl.yaml:

apiVersion: extensions/v1beta1   
kind: Deployment                 
metadata:                        
  name: cas-server-depl          
spec:                            
  replicas: 1                    
  template:                      
    metadata:                    
      labels:                    
        app: cas-server-pod
    spec:                        
      containers:                
      - name: cas-server-pod     
        image: shiny-cas         
        imagePullPolicy: Never
        command: ["puma -C /cas-server/config/puma.rb"]
        ports:
          - containerPort: 100
        volumeMounts:
          - mountPath: /app/logs
            name: cas-server-logs
          - mountPath: /app/config
            name: cas-server-config
          - mountPath: /app/public
            name: cas-server-public
      volumes:
        - name: cas-server-logs
          hostPath:
            path: /cas-server/logs
        - name: cas-server-config
          hostPath:
            path: /cas-server/config
        - name: cas-server-public
          hostPath:
            path: /cas-server/public

In virtual machine, I copy ./cas-server directory to /cas-server, and changed chown and chgrp as my login name k8s, when I do sudo kubectl apply -f cas-server-depl.yaml, it has following response:

[k8s@k8s config]$ sudo kubectl get po
NAME                               READY     STATUS              RESTARTS   AGE
cas-server-depl-7f849bf94c-srg77   0/1       RunContainerError   1          5s

Then I use following command to see why:

[k8s@k8s config]$ sudo kubectl describe po cas-server-depl-7988d6b447-ffff5
Name:               cas-server-depl-7988d6b447-ffff5
Namespace:          default
Priority:           0

IP:                 100.68.142.72
Controlled By:      ReplicaSet/cas-server-depl-7988d6b447
Containers:
  cas-server-pod:

    Command:
      puma -C /cas-server/config/puma.rb
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       ContainerCannotRun
      Message:      OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"puma -C /cas-server/config/puma.rb\": stat puma -C /cas-server/config/puma.rb: no such file or directory": unknown
      Exit Code:    128
      ...
    Ready:          False
    Restart Count:  2
    Environment:    <none>
    Mounts:
      /app/config from cas-server-config (rw)
      /app/logs from cas-server-logs (rw)
      /app/public from cas-server-public (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-mrkdx (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             False
  ContainersReady   False
  PodScheduled      True
Volumes:
  cas-server-logs:
    Type:          HostPath (bare host directory volume)
    Path:          /cas-server/logs
    HostPathType:

    HostPathType:
  default-token-mrkdx:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-mrkdx
    Optional:    false


  Normal   Created    15s (x3 over 29s)  kubelet, k8s.xxx.com.cn  Created container
  Warning  Failed     15s (x3 over 28s)  kubelet, k8s.xxx.com.cn  Error: failed to start container "cas-server-pod": Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"puma -C /cas-server/config/puma.rb\": stat puma -C /cas-server/config/puma.rb: no such file or directory": unknown
  Warning  BackOff    1s (x3 over 26s)   kubelet, k8s.shinyinfo.com.cn  Back-off restarting failed container

It says:

Message:      OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"puma -C /cas-server/config/puma.rb\": stat puma -C /cas-server/config/puma.rb: no such file or directory": unknown

I tried /app/config/puma.rb and config/puma.rb in command, both have same error message. which directory I shall write? I could see puma.rb do exists.

My cas-server-svc.yaml is pasted as reference:

apiVersion: v1
kind: Service
metadata:
  name: cas-server-svc
  labels:
    name: cas-server-svc
spec:
  selector:
    app: cas-server-pod
  type: NodePort
  ports:
  - port: 100
    nodePort: 31101
    name: tcp
-- user84592
docker
kubernetes

3 Answers

11/23/2018

When you say

command: ["puma -C /cas-server/config/puma.rb"]

You are telling Kubernetes to tell Docker to look for a single executable named puma -C ..., where what you think are the command-line options are actually part of the filename. You need to split out the arguments into separate elements in the YAML list syntax, something like

command: ["puma", "-C", "/cas-server/config/puma.rb"]

or

command:
  - puma
  - -C
  - /cas-server/config/puma.rb
-- David Maze
Source: StackOverflow

11/26/2018

@David Maze, @nightfury1204 Thanks both your answer. Each answered the part of the question.

Path shall be /app/config, command line is as follows:

command: ["/bin/sh"]
args: ["-c","puma -C /app/config/puma.rb"]

What's more, one shall also notice /app/config access rights to login user.

-- user84592
Source: StackOverflow

11/23/2018

Path should be /app/config/puma.rb instead of /cas-server/config/puma.rb, since you mounted cas-server-config in /app/config/. Also make sure /cas-server/config/puma.rb file exist in host path.

spec:                        
  containers:                
  - name: cas-server-pod     
    image: shiny-cas         
    imagePullPolicy: Never
    command: ["puma -C /app/config/puma.rb"]
    ports:
      - containerPort: 100
    volumeMounts:
      - mountPath: /app/logs
        name: cas-server-logs
      - mountPath: /app/config
        name: cas-server-config
      - mountPath: /app/public
        name: cas-server-public
  volumes:
    - name: cas-server-logs
      hostPath:
        path: /cas-server/logs
    - name: cas-server-config
      hostPath:
        path: /cas-server/config
    - name: cas-server-public
      hostPath:
        path: /cas-server/public
-- nightfury1204
Source: StackOverflow